KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > mapping > KeyPair


1 // Copyright (c) 2004 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.mapping;
5
6 /** A simple concrete implemementation of <code>EnvironmentKey</code>. */
7
8 public class KeyPair implements EnvironmentKey
9 {
10   Symbol name;
11   Object JavaDoc property;
12
13   public KeyPair (Symbol name, Object JavaDoc property)
14   {
15     this.name = name;
16     this.property = property;
17   }
18
19   public Symbol getKeySymbol () { return name; }
20   public Object JavaDoc getKeyProperty () { return property; }
21
22   public final boolean matches (EnvironmentKey key)
23   {
24     return Symbol.equals(key.getKeySymbol(), this.name)
25       && key.getKeyProperty() == this.property;
26   }
27
28   public final boolean matches (Symbol symbol, Object JavaDoc property)
29   {
30     return Symbol.equals(symbol, this.name) && property == this.property;
31   }
32
33   public boolean equals (Object JavaDoc x)
34   {
35     if (! (x instanceof KeyPair))
36       return false;
37     KeyPair e2 = (KeyPair) x;
38     return property == e2.property
39       && (name == null ? e2.name == null : name.equals(e2.name));
40   }
41
42   public int hashCode ()
43   {
44     return name.hashCode() ^ System.identityHashCode(property);
45   }
46
47   public String JavaDoc toString () { return "KeyPair[sym:"+name+" prop:"+property+"]"; }
48 }
49
Popular Tags