1 22 23 package com.sosnoski.util.hashmap; 24 25 import java.lang.reflect.Array ; 26 import java.util.Iterator ; 27 28 import com.sosnoski.util.ObjectHashBase; 29 import com.sosnoski.util.SparseArrayIterator; 30 31 53 54 public abstract class ObjectKeyBase extends ObjectHashBase 55 { 56 67 68 public ObjectKeyBase(int count, double fill, Class ktype, Class vtype, 69 Object tech) { 70 super(count, fill, ktype, tech); 71 setValueArray(Array.newInstance(vtype, m_arraySize)); 72 } 73 74 79 80 public ObjectKeyBase(ObjectKeyBase from) { 81 super(from); 82 Class type = from.getValueArray().getClass().getComponentType(); 83 Object copy = Array.newInstance(type, m_arraySize); 84 System.arraycopy(from.getValueArray(), 0, copy, 0, m_arraySize); 85 setValueArray(copy); 86 } 87 88 95 96 protected abstract Object getValueArray(); 97 98 105 106 protected abstract void setValueArray(Object array); 107 108 118 119 protected abstract void restructure(Object karray, Object varray); 120 121 129 130 protected void reallocate(int size) { 131 132 Object keys = getKeyArray();; 134 Class type = keys.getClass().getComponentType(); 135 setKeyArray(Array.newInstance(type, size)); 136 Object values = getValueArray(); 137 type = values.getClass().getComponentType(); 138 setValueArray(Array.newInstance(type, size)); 139 140 restructure(keys, values); 142 } 143 144 153 154 protected abstract boolean reinsert(int slot); 155 156 166 167 protected void internalRemove(int slot) { 168 169 Object [] keys = getKeyArray(); 171 keys[slot] = null; 172 m_entryCount--; 173 while (keys[(slot = stepSlot(slot))] != null) { 174 175 reinsert(slot); 177 178 } 179 } 180 181 187 188 public void clear() { 189 super.clear(); 190 Object values = getValueArray(); 191 if (!values.getClass().getComponentType().isPrimitive()) { 192 Object [] objects = (Object [])values; 193 for (int i = 0; i < objects.length; i++) { 194 objects[i] = null; 195 } 196 } 197 } 198 199 207 208 public final Iterator iterator() { 209 return SparseArrayIterator.buildIterator((Object [])getKeyArray()); 210 } 211 } 212 | Popular Tags |