Class Decoratable

  • Direct Known Subclasses:
    Symbol, Token

    public abstract class Decoratable
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Decoratable()
      A decoratable item with no attributes.
      Decoratable​(java.util.Collection<ParserAttribute> attributes)
      A decoratable item with attributes.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addAttribute​(ParserAttribute attribute)
      Add the specified attribute to the attributes collection.
      void addAttributes​(java.util.Collection<ParserAttribute> attrcoll)
      Add the specified attributes to the attributes collection.
      ParserAttribute getAttribute​(java.lang.String name)
      Get a specific token attribute.
      java.util.List<ParserAttribute> getAttributes()
      Get all the token's attributes.
      java.util.Map<java.lang.String,​java.lang.String> getAttributesMap()
      Get all the token's attributes as a map.
      java.lang.String getAttributeValue​(java.lang.String name, java.lang.String defaultValue)
      Get a specific token attribute value.
      boolean hasAttribute​(java.lang.String name)
      Check if a specific attribute is specified.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Decoratable

        public Decoratable()
        A decoratable item with no attributes.
      • Decoratable

        public Decoratable​(java.util.Collection<ParserAttribute> attributes)
        A decoratable item with attributes.
        Parameters:
        attributes - the attributes
        Throws:
        GrammarException - if the attribute names are not unique
        AttributeException - if an attribute has an invalid value
    • Method Detail

      • hasAttribute

        public final boolean hasAttribute​(java.lang.String name)
        Check if a specific attribute is specified.
        Parameters:
        name - the name of the attribute.
        Returns:
        true if the attribute is associated with this token.
      • getAttribute

        public final ParserAttribute getAttribute​(java.lang.String name)
        Get a specific token attribute.
        Parameters:
        name - the name of the attribute.
        Returns:
        the associated attribute, or null if there is no attribute with that name.
      • getAttributeValue

        public final java.lang.String getAttributeValue​(java.lang.String name,
                                                        java.lang.String defaultValue)
        Get a specific token attribute value.
        Parameters:
        name - the name of the attribute.
        defaultValue - the default value.
        Returns:
        the associated attribute value, or the default if there is no attribute with that name.
      • getAttributes

        public final java.util.List<ParserAttribute> getAttributes()
        Get all the token's attributes.
        Returns:
        the attributes.
      • getAttributesMap

        public final java.util.Map<java.lang.String,​java.lang.String> getAttributesMap()
        Get all the token's attributes as a map.
        Returns:
        the associated attribute, or null if there is no attribute with that name.
      • addAttribute

        public final void addAttribute​(ParserAttribute attribute)
        Add the specified attribute to the attributes collection.

        Once added, an attribute cannot be removed, nor can its value be changed.

        Parameters:
        attribute - the attribute
        Throws:
        AttributeException - if you attempt to change the value of an attribute
        AttributeException - if you pass an illegal attribute
        java.lang.NullPointerException - if the attribute is null
      • addAttributes

        public final void addAttributes​(java.util.Collection<ParserAttribute> attrcoll)
        Add the specified attributes to the attributes collection.

        Once added, an attribute cannot be removed, nor can its value be changed.

        Parameters:
        attrcoll - the attributes
        Throws:
        AttributeException - if you attempt to change the value of an attribute
        AttributeException - if you pass an illegal attribute