01: package org.obe.engine.util;
02:
03: /**
04: * Compound key.
05: *
06: * @author Adrian Price
07: */
08: public class CompoundKey {
09: private int hashcode;
10: public final Object[] keys;
11:
12: CompoundKey(Object key0) {
13: keys = new Object[] { key0 };
14: }
15:
16: CompoundKey(Object key0, Object key1) {
17: keys = new Object[] { key0, key1 };
18: }
19:
20: CompoundKey(Object key0, Object key1, Object key2) {
21: keys = new Object[] { key0, key1, key2 };
22: }
23:
24: CompoundKey(Object key0, Object key1, Object key2, Object key3) {
25: keys = new Object[] { key0, key1, key2, key3 };
26: }
27:
28: CompoundKey(Object[] keys) {
29: this .keys = (Object[]) keys.clone();
30: }
31:
32: public boolean equals(Object obj) {
33: if (this == obj)
34: return true;
35: if (!(obj instanceof CompoundKey))
36: return false;
37:
38: CompoundKey that = (CompoundKey) obj;
39: int n = Math.min(keys.length, that.keys.length);
40: for (int i = 0; i < n; i++) {
41: Object this Key = keys[i];
42: Object thatKey = that.keys[i];
43: if (this Key == null || thatKey == null)
44: continue;
45: if (!this Key.equals(thatKey))
46: return false;
47: }
48: return true;
49: }
50:
51: public int hashCode() {
52: if (hashcode == 0) {
53: for (int i = 0; i < keys.length; i++)
54: hashcode += 29 * hashcode + keys[i].hashCode();
55: }
56: return hashcode;
57: }
58: }
|