/** * Constructs an empty <tt>HashMap</tt> with the default initial capacity (16) and the default * load factor (0.75). */ public ObjectIntHashMap(HashingStrategy hs) { this.loadFactor = DEFAULT_LOAD_FACTOR; threshold = (int) (DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR); table = new Entry[DEFAULT_INITIAL_CAPACITY]; this.hashingStrategy = (hs == null) ? new IntHashMapStrategy() : hs; init(); }
/** * Reconstitute the <tt>HashMap</tt> instance from a stream (i.e., deserialize it). */ private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { // Read in the threshold, loadfactor, and any hidden stuff s.defaultReadObject(); // Read in number of buckets and allocate the bucket array; int numBuckets = s.readInt(); table = new Entry[numBuckets]; init(); // Give subclass a chance to do its thing. // Read in size (number of Mappings) int size = s.readInt(); // Read the keys and values, and put the mappings in the IntHashMap for (int i = 0; i < size; i++) { Object key = (Object) s.readObject(); int value = (int) s.readInt(); putForCreate(key, value); } }
/** * Returns a shallow copy of this <tt>HashMap</tt> instance: the keys and values themselves are * not cloned. * * @return a shallow copy of this map */ @Override public Object clone() { ObjectIntHashMap result = null; try { result = (ObjectIntHashMap) super.clone(); } catch (CloneNotSupportedException e) { // assert false; } result.table = new Entry[table.length]; result.entrySet = null; result.modCount = 0; result.size = 0; result.init(); result.putAllForCreate(this); return result; }
/** * Constructs an empty <tt>HashMap</tt> with the specified initial capacity and load factor. * * @param initialCapacity the initial capacity * @param loadFactor the load factor * @throws IllegalArgumentException if the initial capacity is negative or the load factor is * nonpositive */ public ObjectIntHashMap(int initialCapacity, float loadFactor, HashingStrategy hs) { if (initialCapacity < 0) throw new IllegalArgumentException("Illegal initial capacity: " + initialCapacity); if (initialCapacity > MAXIMUM_CAPACITY) initialCapacity = MAXIMUM_CAPACITY; if (loadFactor <= 0 || Float.isNaN(loadFactor)) throw new IllegalArgumentException("Illegal load factor: " + loadFactor); // Find a power of 2 >= initialCapacity int capacity = 1; while (capacity < initialCapacity) capacity <<= 1; this.loadFactor = loadFactor; threshold = (int) (capacity * loadFactor); table = new Entry[capacity]; hashingStrategy = (hs == null) ? new IntHashMapStrategy() : hs; init(); }