KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > util > HashNode


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

4 package gnu.kawa.util;
5
6 /** An entry in a {@link GeneralHashTable}.
7  * This is a public class to allow overriding.
8  */

9
10 public class HashNode
11 /* #ifdef JAVA2 */
12 implements java.util.Map.Entry
13 /* #endif */
14 {
15   public HashNode next;
16   int hash;
17   Object JavaDoc key;
18   Object JavaDoc value;
19
20   public Object JavaDoc get (Object JavaDoc defaultValue)
21   {
22     return value;
23   }
24
25   public Object JavaDoc getKey ()
26   {
27     return key;
28   }
29
30   public Object JavaDoc getValue ()
31   {
32     return value;
33   }
34
35   public Object JavaDoc setValue (Object JavaDoc value)
36   {
37     Object JavaDoc old = this.value;
38     this.value = value;
39     return old;
40   }
41
42   /** Implements the general Map.Entry specification.
43    * But note that a GeneralHashTable subclass may override {@code matches},
44    * so it no longer uses equals, in which case it won't be consistent
45    * with this method, unless it is overridden. */

46   public boolean equals (Object JavaDoc o)
47   {
48     if (! (o instanceof HashNode))
49       return false;
50     HashNode h2 = (HashNode) o;
51     return (key == null ? h2.key == null : key.equals(h2.key))
52       && (value == null ? h2.value == null : value.equals(h2.value));
53   }
54
55   /** Implements the general Map.Entry specification.
56    * But note that a GeneralHashTable subclass may override {@code hash},
57    * so it no longer uses equals, in which case it won't be consistent
58    * with this method, unless it is overridden. */

59   public int hashCode ()
60   {
61     return (key ==null ? 0 : key.hashCode())
62       ^ (value==null ? 0: value.hashCode());
63   }
64 }
65
Popular Tags