KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > client > RSBKey


1 package com.daffodilwoods.daffodildb.client;
2
3 import com.daffodilwoods.database.resource.*;
4
5 public class RSBKey implements Comparable JavaDoc {
6    Object JavaDoc values;
7    private int hash = 0;
8    private RSBKeyComparator comparator;
9    Object JavaDoc rbtreeKey;
10    private Object JavaDoc orderValues;
11
12    public RSBKey(RSBKeyComparator comparator, Object JavaDoc rbtreeKey, Object JavaDoc values) {
13       this.values = values;
14       this.comparator = comparator;
15       this.rbtreeKey = rbtreeKey;
16       try {
17          this.orderValues = comparator.getOrderValues(values);
18       } catch (DException ex) {
19          throw new RuntimeException JavaDoc(ex.getMessage());
20       }
21    }
22
23    public int hashCode() {
24       int hashCode = hash;
25       if (hashCode == 0) {
26          if (orderValues != null && (orderValues instanceof Object JavaDoc[])) {
27             Object JavaDoc[] values = (Object JavaDoc[]) orderValues;
28             for (int i = 0; i < values.length; i++)
29                hashCode += values[i] == null ?
30                    Integer.MIN_VALUE : values[i].hashCode();
31          } else
32             hashCode = orderValues == null ? -1 : orderValues.hashCode();
33       }
34       return hashCode;
35    }
36
37    public int compareTo(Object JavaDoc rsbKey) {
38       if (! (rsbKey instanceof RSBKey)) {
39          ;//// Removed By Program ** System.out.println("RsbKey = " + rsbKey.getClass());
40
throw new RuntimeException JavaDoc("Parameter passed is "+rsbKey.toString());
41       }
42       try {
43          return comparator.getComparator().compare(orderValues, ( (RSBKey) rsbKey).orderValues);
44       } catch (DException ex) {
45          throw new RuntimeException JavaDoc(ex.getMessage());
46       }
47    }
48
49    public boolean equals(Object JavaDoc object) {
50       if (! (object instanceof RSBKey))
51          return false;
52       return compareTo(object) == 0;
53    }
54
55    public String JavaDoc toString() {
56       return orderValues == null ? "" : java.util.Arrays.asList( (Object JavaDoc[]) orderValues).toString();
57    }
58 }
59
Popular Tags