KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > tokens > TypedToken


1 package jfun.parsec.tokens;
2 /**
3  * Represents a token associated with a token type.
4  * <p>
5  * @author Ben Yu
6  * Apr 27, 2006 8:01:19 PM
7  * @since version 1.1
8  */

9 public class TypedToken<Type> extends NamedToken {
10   private final Type type;
11
12   public TypedToken(String JavaDoc name, Type type) {
13     super(name);
14     this.type = type;
15   }
16   /**
17    * Get the text of the token. Equivalent to {@link #getName()}.
18    * @since version 0.6
19    */

20   public final String JavaDoc getText(){
21     return getName();
22   }
23   /**
24    * To get the data type of the token.
25    */

26   public Type getType() {
27     return type;
28   }
29   public boolean equals(TypedToken other){
30     return type.equals(other.type) && super.equals(other);
31   }
32   public boolean equals(Object JavaDoc obj) {
33     if(obj instanceof TypedToken){
34       return equals((TypedToken)obj);
35     }
36     else return false;
37   }
38
39   public int hashCode() {
40     return type.hashCode() * 31 + super.hashCode();
41   }
42 }
43
Popular Tags