KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sablecc > sablecc > structure > Token


1 /* This file is part of SableCC ( http://sablecc.org ).
2  *
3  * Copyright 2007 Etienne M. Gagnon <egagnon@j-meg.com>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.sablecc.sablecc.structure;
19
20 import org.sablecc.sablecc.exception.InternalException;
21
22 public class Token
23         implements Comparable JavaDoc<Token> {
24
25     private final String JavaDoc name;
26
27     private final Group group;
28
29     Token(
30             String JavaDoc name,
31             Group group) {
32
33         if (name == null) {
34             throw new InternalException("name may not be null");
35         }
36
37         if (group == null) {
38             throw new InternalException("group may not be null");
39         }
40
41         this.name = name;
42         this.group = group;
43
44         group.addToken(this);
45     }
46
47     public String JavaDoc getName() {
48
49         return this.name;
50     }
51
52     public Group getGroup() {
53
54         return this.group;
55     }
56
57     @Override JavaDoc
58     public boolean equals(
59             Object JavaDoc obj) {
60
61         if (this == obj) {
62             return true;
63         }
64
65         if (obj == null) {
66             return false;
67         }
68
69         if (getClass() != obj.getClass()) {
70             return false;
71         }
72
73         Token token = (Token) obj;
74
75         return this.name.equals(token.name);
76     }
77
78     @Override JavaDoc
79     public int hashCode() {
80
81         return this.name.hashCode();
82     }
83
84     public int compareTo(
85             Token token) {
86
87         return this.name.compareTo(token.name);
88     }
89
90 }
91
Popular Tags