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: public class Choice implements Named {
14:
15: private final Name name;
16: private Namespace funcNS = new Namespace();
17: private final String category;
18:
19: /**
20: * creates a choice object with name <category>:<choice>.
21: */
22: public Choice(String choice, String category) {
23: this (new Name(category + ":" + choice), category);
24: }
25:
26: public Choice(Name name, String category) {
27: this .name = name;
28: // .intern() crucial for correct equals
29: this .category = category.intern();
30: }
31:
32: public Choice(Name name) {
33: this .name = name;
34: category = null;
35: }
36:
37: public Name name() {
38: return name;
39: }
40:
41: public String category() {
42: return category;
43: }
44:
45: public Namespace funcNS() {
46: return funcNS;
47: }
48:
49: public void setFuncNS(Namespace funcNS) {
50: this .funcNS = funcNS;
51: }
52:
53: public boolean equals(Object o) {
54: if (!(o instanceof Choice)) {
55: return false;
56: }
57: final Choice c = (Choice) o;
58: return category == c.category && name.equals(c.name);
59:
60: }
61:
62: public int hashCode() {
63: return name.hashCode() * 37
64: + (category == null ? 13 : category.hashCode() * 1369);
65: }
66:
67: public Choice copy() {
68: Choice c;
69: if (category == null) {
70: c = new Choice(name);
71: } else {
72: c = new Choice(name, category);
73: }
74: c.setFuncNS(funcNS.copy());
75: return c;
76: }
77:
78: public String toString() {
79: return name.toString();
80: }
81:
82: }
|