import Token; /** * Tokens that take parameters, such as identifiers and numbers. * Make sure to create these tokens with * ParameterizedToken.build(String) * rather than * new ParameterizedToken(...) * * @author Samuel A. Rebelsky * @version 1.0 of February 2001. */ public class ParameterizedToken extends Token { // +--------+-------------------------------------------------- // | Fields | // +--------+ /** The value associated with the token. */ protected String value; // +--------------+-------------------------------------------- // | Constructors | // +--------------+ /** * Create a new parameterized token with a particular value. */ public ParameterizedToken(String val) { this.value = val; } // ParameterizedToken(String) // +----------------+------------------------------------------ // | Static Methods | // +----------------+ /** * Build a new token. */ public static Token build(String val) { return new ParameterizedToken(val); } // build(String) // +---------+------------------------------------------------- // | Methods | // +---------+ /** * Convert to a string for easy printing. */ public String toString() { return "PARAMETERIZED(" + this.value + ")"; } // toString() /** * Determine if this token equals another object. That * only happens if both are ParameterizedTokens and they * have the same value. * * Warning! Subclasses should probably override this method. * Otherwise, two different tokens with the same parameter * will be treated as equal. */ public boolean equals(Object other) { return ( (other instanceof ParameterizedToken) && (this.equals((ParameterizedToken) other)) ); } // equals(Object) /** * Determine if this token equals another parameterized token. * That only happens if they have the same associated value. * * While subclasses may not need to override this method, they * may want to provide a more restricted version. */ public boolean equals(ParameterizedToken other) { return this.value.equals(other.value); } // equals(ParameterizedToken) } // class ParameterizedToken