KeyPair.java 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2004 Per M.A. Bothner.
  2. // This is free software; for terms and warranty disclaimer see ./COPYING.
  3. package gnu.mapping;
  4. /** A simple concrete implemementation of <code>EnvironmentKey</code>. */
  5. public class KeyPair implements EnvironmentKey
  6. {
  7. Symbol name;
  8. Object property;
  9. public KeyPair (Symbol name, Object property)
  10. {
  11. this.name = name;
  12. this.property = property;
  13. }
  14. public Symbol getKeySymbol () { return name; }
  15. public Object getKeyProperty () { return property; }
  16. public final boolean matches (EnvironmentKey key)
  17. {
  18. return Symbol.equals(key.getKeySymbol(), this.name)
  19. && key.getKeyProperty() == this.property;
  20. }
  21. public final boolean matches (Symbol symbol, Object property)
  22. {
  23. return Symbol.equals(symbol, this.name) && property == this.property;
  24. }
  25. public boolean equals (Object x)
  26. {
  27. if (! (x instanceof KeyPair))
  28. return false;
  29. KeyPair e2 = (KeyPair) x;
  30. return property == e2.property
  31. && (name == null ? e2.name == null : name.equals(e2.name));
  32. }
  33. public int hashCode ()
  34. {
  35. return name.hashCode() ^ System.identityHashCode(property);
  36. }
  37. public String toString () { return "KeyPair[sym:"+name+" prop:"+property+"]"; }
  38. }