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 property;
12 
KeyPair(Symbol name, Object property)13   public KeyPair (Symbol name, Object property)
14   {
15     this.name = name;
16     this.property = property;
17   }
18 
getKeySymbol()19   public Symbol getKeySymbol () { return name; }
getKeyProperty()20   public Object getKeyProperty () { return property; }
21 
matches(EnvironmentKey key)22   public final boolean matches (EnvironmentKey key)
23   {
24     return Symbol.equals(key.getKeySymbol(), this.name)
25       && key.getKeyProperty() == this.property;
26   }
27 
matches(Symbol symbol, Object property)28   public final boolean matches (Symbol symbol, Object property)
29   {
30     return Symbol.equals(symbol, this.name) && property == this.property;
31   }
32 
equals(Object x)33   public boolean equals (Object 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 
hashCode()42   public int hashCode ()
43   {
44     return name.hashCode() ^ System.identityHashCode(property);
45   }
46 
toString()47   public String toString () { return "KeyPair[sym:"+name+" prop:"+property+"]"; }
48 }
49