01: // Copyright (c) 2005 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see COPYING.
03:
04: package gnu.kawa.util;
05:
06: /** An entry in a {@link GeneralHashTable}.
07: * This is a public class to allow overriding.
08: */
09:
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 key;
18: Object value;
19:
20: public Object get(Object defaultValue) {
21: return value;
22: }
23:
24: public Object getKey() {
25: return key;
26: }
27:
28: public Object getValue() {
29: return value;
30: }
31:
32: public Object setValue(Object value) {
33: Object old = this .value;
34: this .value = value;
35: return old;
36: }
37:
38: /** Implements the general Map.Entry specification.
39: * But note that a GeneralHashTable subclass may override {@code matches},
40: * so it no longer uses equals, in which case it won't be consistent
41: * with this method, unless it is overridden. */
42: public boolean equals(Object o) {
43: if (!(o instanceof HashNode))
44: return false;
45: HashNode h2 = (HashNode) o;
46: return (key == null ? h2.key == null : key.equals(h2.key))
47: && (value == null ? h2.value == null : value
48: .equals(h2.value));
49: }
50:
51: /** Implements the general Map.Entry specification.
52: * But note that a GeneralHashTable subclass may override {@code hash},
53: * so it no longer uses equals, in which case it won't be consistent
54: * with this method, unless it is overridden. */
55: public int hashCode() {
56: return (key == null ? 0 : key.hashCode())
57: ^ (value == null ? 0 : value.hashCode());
58: }
59: }
|