KickJava   Java API By Example, From Geeks To Geeks.

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


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 State
23         implements Comparable JavaDoc<State> {
24
25     private final String JavaDoc name;
26
27     State(
28             String JavaDoc name) {
29
30         this.name = name;
31     }
32
33     public boolean hasName() {
34
35         return this.name != null;
36     }
37
38     public String JavaDoc getName() {
39
40         if (this.name == null) {
41             throw new InternalException("this state does not have a name");
42         }
43
44         return this.name;
45     }
46
47     @Override JavaDoc
48     public boolean equals(
49             Object JavaDoc obj) {
50
51         if (this == obj) {
52             return true;
53         }
54
55         if (obj == null) {
56             return false;
57         }
58
59         if (getClass() != obj.getClass()) {
60             return false;
61         }
62
63         State state = (State) obj;
64
65         if (this.name == null) {
66             return this.name == state.name;
67         }
68
69         return this.name.equals(state.name);
70     }
71
72     @Override JavaDoc
73     public int hashCode() {
74
75         if (this.name == null) {
76             return 0;
77         }
78
79         return this.name.hashCode();
80     }
81
82     public int compareTo(
83             State state) {
84
85         if (this.name == null) {
86             if (state.name == null) {
87                 return 0;
88             }
89
90             return -1;
91         }
92         else if (state == null) {
93             return 1;
94         }
95
96         return this.name.compareTo(state.name);
97     }
98
99 }
100
Popular Tags