01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.logic;
12:
13: /**
14: * A Name object is created to represent the name of an object which
15: * usually implements the interface {@link Named}.
16: */
17: public class Name {
18:
19: protected final String nameString;
20:
21: private final int hashCode;
22:
23: /**
24: * creates a name object
25: *
26: *
27: */
28: public Name(String n) {
29: // .intern() is crucial for correct equals and performance
30: nameString = ((n == null) ? "_noname_" : n).intern();
31: hashCode = nameString.hashCode();
32: }
33:
34: public String toString() {
35: return nameString;
36: }
37:
38: public boolean equals(Object o) {
39: if (!(o instanceof Name)) {
40: return false;
41: }
42: return nameString.equals(((Name) o).nameString);
43: }
44:
45: public int compareTo(Object o) {
46: return nameString.compareTo(((Name) o).nameString);
47: }
48:
49: public int hashCode() {
50: return hashCode;
51: }
52:
53: }
|