01: // Copyright (c) 2004 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.mapping;
05:
06: /** A simple concrete implemementation of <code>EnvironmentKey</code>. */
07:
08: public class KeyPair implements EnvironmentKey {
09: Symbol name;
10: Object property;
11:
12: public KeyPair(Symbol name, Object property) {
13: this .name = name;
14: this .property = property;
15: }
16:
17: public Symbol getKeySymbol() {
18: return name;
19: }
20:
21: public Object getKeyProperty() {
22: return property;
23: }
24:
25: public final boolean matches(EnvironmentKey key) {
26: return Symbol.equals(key.getKeySymbol(), this .name)
27: && key.getKeyProperty() == this .property;
28: }
29:
30: public final boolean matches(Symbol symbol, Object property) {
31: return Symbol.equals(symbol, this .name)
32: && property == this .property;
33: }
34:
35: public boolean equals(Object x) {
36: if (!(x instanceof KeyPair))
37: return false;
38: KeyPair e2 = (KeyPair) x;
39: return property == e2.property
40: && (name == null ? e2.name == null : name
41: .equals(e2.name));
42: }
43:
44: public int hashCode() {
45: return name.hashCode() ^ System.identityHashCode(property);
46: }
47:
48: public String toString() {
49: return "KeyPair[sym:" + name + " prop:" + property + "]";
50: }
51: }
|