1 package jfun.yan.element; 2 3 import java.util.Arrays ; 4 import java.util.Map ; 5 6 import jfun.util.Misc; 7 import jfun.util.StringUtils; 8 9 15 public class MapStore<K,T> implements ElementStore<T> { 16 private final java.util.Map <K,T> store; 17 private final K[] keys; 18 19 24 public MapStore(K[] keys, Map <K,T> store) { 25 this.keys = keys; 26 this.store = store; 27 } 28 29 public void storeElement(int ind, T obj) { 30 store.put(keys[ind], obj); 31 } 32 33 public void checkElement(int ind, Class type) { 34 if(ind > keys.length) 35 throw new ArrayIndexOutOfBoundsException (ind); 36 } 37 38 41 public Object [] getKeys() { 42 return keys; 43 } 44 45 48 public java.util.Map <K,T> getMap() { 49 return store; 50 } 51 52 public boolean equals(Object obj) { 53 if(obj instanceof MapStore){ 54 final MapStore other = (MapStore)obj; 55 return store==other.store && Arrays.equals(keys, other.keys); 56 } 57 else return false; 58 } 59 60 public int hashCode() { 61 int hcode = System.identityHashCode(store); 62 for(int i=0; i<keys.length; i++){ 63 hcode = hcode*31+keys[i].hashCode(); 64 } 65 return hcode; 66 } 67 68 public String toString() { 69 final StringBuffer buf = new StringBuffer (); 70 buf.append(Misc.getTypeName(store.getClass())); 71 StringUtils.listArray(buf, "{", ",", "}", keys); 72 return buf.toString(); 73 } 74 75 } 76 | Popular Tags |