KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*****************************************************************************
2  * Copyright (C) Zephyr Business Solutions Corp. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8 /*
9  * Created on Dec 9, 2004
10  *
11  * Author Ben Yu
12  */

13 package jfun.parsec.tokens;
14
15 /**
16  * A token that has a name.
17  * The name is used in error reporting.
18  * @author Ben Yu
19  *
20  * Dec 9, 2004
21  */

22 public class NamedToken implements java.io.Serializable JavaDoc{
23   private final String JavaDoc name;
24   
25   /**
26    * @param name
27    */

28   NamedToken(final String JavaDoc name) {
29     this.name = name;
30   }
31   /**
32    * Get the name.
33    * @return Returns the name.
34    */

35   public final String JavaDoc getName() {
36     return name;
37   }
38   /*
39    * Return the name of the token.
40    * @see java.lang.Object#toString()
41    */

42   public String JavaDoc toString(){
43     return name;
44   }
45   
46   public boolean equals(Object JavaDoc obj) {
47     if(obj instanceof NamedToken){
48       final NamedToken nt2 = (NamedToken)obj;
49       return name.equals(nt2.name);
50     }
51     else return false;
52   }
53   public int hashCode() {
54     return name.hashCode();
55   }
56 }
57
Popular Tags