Class Token


  • public final class Token
    extends Object
    Contains the token's type, corresponding Java object, raw text and the input line number where the token was found. This class is immutable.
    Author:
    Charles Rapp
    • Constructor Detail

      • Token

        public Token​(int type,
                     Object value,
                     String token,
                     int line)
        Creates a token with the given attributes.
        Parameters:
        type - The token type. See TokenLexer for the token type list.
        value - The token value created from raw token string.
        token - The raw token string.
        line - The input line where the token was found.
    • Method Detail

      • type

        public int type()
        Returns the token type.
        Returns:
        the token type.
      • value

        public Object value()
        Returns the token value.
        Returns:
        the token value.
      • token

        public String token()
        Returns the raw token string.
        Returns:
        the raw token string.
      • lineNumber

        public int lineNumber()
        Returns the input line number where the token was found.
        Returns:
        the input line number where the token was found.
      • isValue

        public boolean isValue​(Object value)
        Returns true if value equals the token value and false otherwise.
        Parameters:
        value - Test equality between this object and the token value.
        Returns:
        true if value equals the token value and false otherwise.
      • equals

        public boolean equals​(Object o)
        Returns true if o is a non-null Token instance of the same type and raw token text; false otherwise.
        Overrides:
        equals in class Object
        Parameters:
        o - Test equality with this object.
        Returns:
        true if o is a non-null Token instance of the same type and raw token text; false otherwise.
      • hashCode

        public int hashCode()
        Returns the token hashcode based on the raw token string.
        Overrides:
        hashCode in class Object
        Returns:
        the token hashcode based on the raw token string.
      • toString

        public String toString()
        Returns this token's textual representation.
        Overrides:
        toString in class Object
        Returns:
        this token's textual representation.