/**
 * Represents a Token that has a type (of enum class <code>Type</code>) and
 * a value (of class <code>String</code>).
 * 
 * @author David Matuszek
 * @version Jan 9, 2006
 */
public class Token {    
    Type type;
    String value;
    
    /**
     * Constructor for Token objects.
     * @param type A flag indicating how this Token is classified.
     * @param value The constituent characters of this Token.
     */
    public Token(Type type, String value) {
        this.type = type;
        this.value = value;
        if (type == null || value == null) {
            throw new IllegalArgumentException();
        }
    }
    
    /**
     * Tests whether the given Token is equal to this Token in both
     * type and value.
     * @return <code>true</code> if the Tokens are equal.
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Token)) {
            return false;
        }
        Token that = (Token) o;
        return this.type.equals(that.type) && this.value.equals(that.value);
    }
    /**
     * Returns a String of the form "Type:value".
     * @return A String representation of this Token.
     * @see java.lang.Object#toString()
     */
    @Override public String toString() {
        return type + ":" + value;
    }
}
