staticfinalinthash(Object key) { int h; return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16); } privatevoidreadObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { // Read in the threshold (ignored), loadfactor, and any hidden stuff s.defaultReadObject(); reinitialize(); if (loadFactor <= 0 || Float.isNaN(loadFactor)) thrownewInvalidObjectException("Illegal load factor: " + loadFactor); s.readInt(); // Read and ignore number of buckets intmappings= s.readInt(); // Read number of mappings (size) if (mappings < 0) thrownewInvalidObjectException("Illegal mappings count: " + mappings); elseif (mappings > 0) { // (if zero, use defaults) // Size the table using given load factor only if within // range of 0.25...4.0 floatlf= Math.min(Math.max(0.25f, loadFactor), 4.0f); floatfc= (float)mappings / lf + 1.0f; intcap= ((fc < DEFAULT_INITIAL_CAPACITY) ? DEFAULT_INITIAL_CAPACITY : (fc >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : tableSizeFor((int)fc)); floatft= (float)cap * lf; threshold = ((cap < MAXIMUM_CAPACITY && ft < MAXIMUM_CAPACITY) ? (int)ft : Integer.MAX_VALUE);
// Check Map.Entry[].class since it's the nearest public type to // what we're actually creating. SharedSecrets.getJavaOISAccess().checkArray(s, Map.Entry[].class, cap); @SuppressWarnings({"rawtypes","unchecked"}) Node<K,V>[] tab = (Node<K,V>[])newNode[cap]; table = tab;
// Read the keys and values, and put the mappings in the HashMap for (inti=0; i < mappings; i++) { @SuppressWarnings("unchecked") Kkey= (K) s.readObject(); @SuppressWarnings("unchecked") Vvalue= (V) s.readObject(); putVal(hash(key), key, value, false, false); } } }