01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2004 Robert Grimm
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * version 2 as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.parser;
20:
21: import xtc.tree.Node;
22:
23: /**
24: * A case within a character switch.
25: *
26: * @see CharSwitch
27: *
28: * @author Robert Grimm
29: * @version $Revision: 1.5 $
30: */
31: public class CharCase extends Node {
32:
33: /**
34: * The characters as a character class. Note that the character
35: * class must not be exclusive and should be {@link
36: * CharClass#normalize() normalized}.
37: */
38: public CharClass klass;
39:
40: /**
41: * The optional element. A <code>null</code> element indicates that
42: * this character case's characters do not provide a match.
43: */
44: public Element element;
45:
46: /**
47: * Create a new character case.
48: *
49: * @param klass The character class.
50: */
51: public CharCase(CharClass klass) {
52: this (klass, null);
53: }
54:
55: /**
56: * Create a new character case.
57: *
58: * @param c The character.
59: * @param element The element.
60: */
61: public CharCase(char c, Element element) {
62: this .klass = new CharClass(c);
63: this .element = element;
64: }
65:
66: /**
67: * Create a new character case.
68: *
69: * @param klass The character class.
70: * @param element The element.
71: */
72: public CharCase(CharClass klass, Element element) {
73: this .klass = klass;
74: this .element = element;
75: }
76:
77: public int hashCode() {
78: return klass.hashCode();
79: }
80:
81: public boolean equals(Object o) {
82: if (this == o)
83: return true;
84: if (!(o instanceof CharCase))
85: return false;
86: CharCase other = (CharCase) o;
87: if (!klass.equals(other.klass))
88: return false;
89: if (null == element) {
90: return (null == other.element);
91: } else {
92: return element.equals(other.element);
93: }
94: }
95:
96: }
|