Class SimpleToken<D,T>

java.lang.Object
eu.bandm.tools.lexic.SimpleToken<D,T>
Type Parameters:
D - the type of source document identifiers
T - the type of token types; typically an enum type
All Implemented Interfaces:
Token<D,T>

public class SimpleToken<D,T> extends Object implements Token<D,T>
Simple immutable token implementation.
  • Constructor Details

    • SimpleToken

      public SimpleToken(T type, @Opt @Opt String text, @Opt @Opt Location<D> location)
      Creates a new instance.

      Note that null values for token text and location are generally meaningful. Whether null token types are also valid depends on the application. If T is an enum type, it does not. However, in order to accomodate the general case, this constructor does not check the parameter type for null values either.

      Parameters:
      type - the token type
      text - the token text, or null if not available
      location - the token location, or null if not available
  • Method Details

    • getLocation

      @Opt public @Opt Location<D> getLocation()
      Returns the source location of this token.

      The default implementation returns null.

      Specified by:
      getLocation in interface Token<D,T>
      Returns:
      the source location of this token, or null if not available.
    • getType

      public T getType()
      Returns the type of this token.
      Specified by:
      getType in interface Token<D,T>
      Returns:
      the type of this token.
    • getText

      @Opt public @Opt String getText()
      Returns the text content of this token.

      The default implementation returns null.

      Specified by:
      getText in interface Token<D,T>
      Returns:
      the text content of this token, or null if not available.
    • withType

      public SimpleToken<D,T> withType(T type)
      Returns a token that differs from this token only by a change of token type.
      Specified by:
      withType in interface Token<D,T>
      Parameters:
      type - the type of the new token
      Returns:
      a token that differs from this token only by having the given token type instead
    • toString

      public String toString()
      Evident
      Overrides:
      toString in class Object