1 22 23 package com.sosnoski.util.hashmap; 24 25 import java.lang.reflect.Array ; 26 import com.sosnoski.util.PrimitiveHashBase; 27 28 50 51 public abstract class PrimitiveKeyBase extends PrimitiveHashBase 52 { 53 61 62 public PrimitiveKeyBase(int count, double fill, Class ktype, Class vtype) { 63 super(count, fill, ktype); 64 setValueArray(Array.newInstance(vtype, m_flagTable.length)); 65 } 66 67 72 73 public PrimitiveKeyBase(PrimitiveKeyBase base) { 74 super(base); 75 int size = base.m_flagTable.length; 76 Class type = base.getValueArray().getClass().getComponentType(); 77 Object copy = Array.newInstance(type, size); 78 System.arraycopy(base.getValueArray(), 0, copy, 0, size); 79 setValueArray(copy); 80 } 81 82 89 90 protected abstract Object getValueArray(); 91 92 99 100 protected abstract void setValueArray(Object array); 101 102 113 114 protected abstract void restructure(boolean[] flags, Object karray, 115 Object varray); 116 117 125 126 protected void reallocate(int size) { 127 128 boolean[] flags = m_flagTable; 130 m_flagTable = new boolean[size]; 131 Object keys = getKeyArray();; 132 Class type = keys.getClass().getComponentType(); 133 setKeyArray(Array.newInstance(type, size)); 134 Object values = getValueArray(); 135 type = values.getClass().getComponentType(); 136 setValueArray(Array.newInstance(type, size)); 137 138 restructure(flags, keys, values); 140 } 141 142 148 149 public void clear() { 150 super.clear(); 151 Object values = getValueArray(); 152 if (!values.getClass().getComponentType().isPrimitive()) { 153 Object [] objects = (Object [])values; 154 for (int i = 0; i < objects.length; i++) { 155 objects[i] = null; 156 } 157 } 158 } 159 } 160 | Popular Tags |