01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2007 New York University
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public License
07: * version 2.1 as published by the Free Software Foundation.
08: *
09: * This library 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 GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.typical;
20:
21: /**
22: * The superclass of all variants.
23: *
24: * @author Laune Harris
25: * @author Robert Grimm
26: * @version $Revision: 1.3 $
27: */
28: public abstract class Variant<T extends Tuple> {
29:
30: /** The variant's tuple. */
31: protected T tuple;
32:
33: /**
34: * Create a new variant.
35: *
36: * @param tuple The tuple.
37: */
38: public Variant(T tuple) {
39: this .tuple = tuple;
40: }
41:
42: /** Create a new variant. */
43: protected Variant() {
44: // empty
45: }
46:
47: /**
48: * Get this variant's name.
49: *
50: * @return The name.
51: */
52: public abstract String getName();
53:
54: /**
55: * Get this variant's tuple.
56: *
57: * @return The tuple.
58: */
59: public T getTuple() {
60: return tuple;
61: }
62:
63: public int hashCode() {
64: return getName().hashCode() + 7 * tuple.hashCode();
65: }
66:
67: public boolean equals(Object o) {
68: if (this == o)
69: return true;
70: if (!(o instanceof Variant))
71: return false;
72: Variant<?> other = (Variant<?>) o;
73: return getName().equals(other.getName())
74: && tuple.equals(other.tuple);
75: }
76:
77: public String toString() {
78: return getName() + tuple.toString();
79: }
80:
81: }
|