1 21 22 package org.apache.derby.iapi.store.access; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 26 29 public class KeyHasher 30 { 31 32 private final Object [] objects; 33 34 public KeyHasher(int size) 35 { 36 objects = new Object [size]; 37 } 38 39 45 public void setObject(int index, Object object) 46 { 47 objects[index] = object; 48 } 49 50 57 public Object getObject(int index) 58 { 59 return objects[index]; 60 } 61 62 75 public static Object buildHashKey(Object [] objects, 76 int[] indexes) 77 { 78 if (indexes.length == 1) 80 { 81 return objects[indexes[0]]; 82 } 83 84 KeyHasher mh = new KeyHasher(indexes.length); 86 for (int index = 0; index < indexes.length; index++) 87 { 88 mh.setObject(index, objects[indexes[index]]); 89 } 90 return mh; 91 } 92 93 96 97 public int hashCode() 98 { 99 int retval = 0; 100 for (int index = 0; index < objects.length; index++) 101 { 102 retval += objects[index].hashCode(); 103 } 104 105 return retval; 106 } 107 108 public boolean equals(Object obj) 109 { 110 if (!(obj instanceof KeyHasher)) 111 return false; 112 113 KeyHasher mh = (KeyHasher) obj; 114 115 if (mh.objects.length != objects.length) 116 return false; 117 118 for (int index = 0; index < objects.length; index++) 119 { 120 if (! (mh.objects[index].equals(objects[index]))) 121 { 122 return false; 123 } 124 } 125 126 return true; 127 } 128 } 129 | Popular Tags |