1 package com.daffodilwoods.daffodildb.client; 2 3 import com.daffodilwoods.database.resource.*; 4 5 public class RSBKey implements Comparable { 6 Object values; 7 private int hash = 0; 8 private RSBKeyComparator comparator; 9 Object rbtreeKey; 10 private Object orderValues; 11 12 public RSBKey(RSBKeyComparator comparator, Object rbtreeKey, Object 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 (ex.getMessage()); 20 } 21 } 22 23 public int hashCode() { 24 int hashCode = hash; 25 if (hashCode == 0) { 26 if (orderValues != null && (orderValues instanceof Object [])) { 27 Object [] values = (Object []) 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 rsbKey) { 38 if (! (rsbKey instanceof RSBKey)) { 39 ; throw new RuntimeException ("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 (ex.getMessage()); 46 } 47 } 48 49 public boolean equals(Object object) { 50 if (! (object instanceof RSBKey)) 51 return false; 52 return compareTo(object) == 0; 53 } 54 55 public String toString() { 56 return orderValues == null ? "" : java.util.Arrays.asList( (Object []) orderValues).toString(); 57 } 58 } 59 | Popular Tags |