194 private Entry<K,V>[] newTable(int n) {
195 return (Entry<K,V>[]) new Entry<?,?>[n];
196 }
197
198 /**
199 * Constructs a new, empty {@code WeakHashMap} with the given initial
200 * capacity and the given load factor.
201 *
202 * @param initialCapacity The initial capacity of the {@code WeakHashMap}
203 * @param loadFactor The load factor of the {@code WeakHashMap}
204 * @throws IllegalArgumentException if the initial capacity is negative,
205 * or if the load factor is nonpositive.
206 */
207 public WeakHashMap(int initialCapacity, float loadFactor) {
208 if (initialCapacity < 0)
209 throw new IllegalArgumentException("Illegal Initial Capacity: "+
210 initialCapacity);
211 if (initialCapacity > MAXIMUM_CAPACITY)
212 initialCapacity = MAXIMUM_CAPACITY;
213
214 if (loadFactor <= 0 || Float.isNaN(loadFactor))
215 throw new IllegalArgumentException("Illegal Load factor: "+
216 loadFactor);
217 int capacity = 1;
218 while (capacity < initialCapacity)
219 capacity <<= 1;
220 table = newTable(capacity);
221 this.loadFactor = loadFactor;
222 threshold = (int)(capacity * loadFactor);
223 }
224
225 /**
226 * Constructs a new, empty {@code WeakHashMap} with the given initial
227 * capacity and the default load factor (0.75).
228 *
229 * @param initialCapacity The initial capacity of the {@code WeakHashMap}
230 * @throws IllegalArgumentException if the initial capacity is negative
231 */
232 public WeakHashMap(int initialCapacity) {
233 this(initialCapacity, DEFAULT_LOAD_FACTOR);
234 }
235
|
194 private Entry<K,V>[] newTable(int n) {
195 return (Entry<K,V>[]) new Entry<?,?>[n];
196 }
197
198 /**
199 * Constructs a new, empty {@code WeakHashMap} with the given initial
200 * capacity and the given load factor.
201 *
202 * @param initialCapacity The initial capacity of the {@code WeakHashMap}
203 * @param loadFactor The load factor of the {@code WeakHashMap}
204 * @throws IllegalArgumentException if the initial capacity is negative,
205 * or if the load factor is nonpositive.
206 */
207 public WeakHashMap(int initialCapacity, float loadFactor) {
208 if (initialCapacity < 0)
209 throw new IllegalArgumentException("Illegal Initial Capacity: "+
210 initialCapacity);
211 if (initialCapacity > MAXIMUM_CAPACITY)
212 initialCapacity = MAXIMUM_CAPACITY;
213
214 if (!(loadFactor > 0)) // also checks for NaNs
215 throw new IllegalArgumentException("Illegal load factor: " +
216 loadFactor);
217 int capacity = 1;
218 while (capacity < initialCapacity)
219 capacity <<= 1;
220 table = newTable(capacity);
221 this.loadFactor = loadFactor;
222 threshold = (int)(capacity * loadFactor);
223 }
224
225 /**
226 * Constructs a new, empty {@code WeakHashMap} with the given initial
227 * capacity and the default load factor (0.75).
228 *
229 * @param initialCapacity The initial capacity of the {@code WeakHashMap}
230 * @throws IllegalArgumentException if the initial capacity is negative
231 */
232 public WeakHashMap(int initialCapacity) {
233 this(initialCapacity, DEFAULT_LOAD_FACTOR);
234 }
235
|