package rebelsky.cs362;

/**
 * Simple identifiers for a tokenizer.
 *
 * @author Samuel A. Rebelsky
 * @version 0.1 of July 2002
 */
public class Identifier
  implements Token
{

  // +--------+-------------------------------------------------------------
  // | Fields |
  // +--------+

  /** The value of the identifier. */
  private String value;

  // +--------------+-------------------------------------------------------
  // | Constructors |
  // +--------------+

  public Identifier(String idval) {
    this.value = idval;
  } // Identifier(String)


  // +-----------+----------------------------------------------------------
  // | Observers |
  // +-----------+

  /**
   * Convert the token to a string (e.g., for printing).
   */
  public String toString() {
    return "ID[" + this.value + "]";
  } // toString

  /**
   * Determine if the token is the same as another token.
   */
  public boolean equals(Token other) {
    try {
      return this.equals((Identifier) other);
    }
    catch (ClassCastException cce) {
      return false;
    }
  } // equals(Token)

  public boolean equals(Identifier other) {
    return this.value.equals(other.value);
  } // equals(Identifier)

} // class Identifier

