28 |
|
|
29 |
package java.util; |
package java.util; |
30 |
|
|
|
import java.io.IOException; |
|
|
import java.io.Serializable; |
|
|
import java.io.ObjectInputStream; |
|
|
import java.io.ObjectOutputStream; |
|
|
|
|
31 |
/** |
/** |
32 |
* This class provides a hashtable-backed implementation of the |
* This class provides a hashtable-backed implementation of the |
33 |
* Map interface, with predictable traversal order. |
* Map interface, with predictable traversal order. |
84 |
* @see TreeMap |
* @see TreeMap |
85 |
* @see Hashtable |
* @see Hashtable |
86 |
* @since 1.4 |
* @since 1.4 |
87 |
|
* @status updated to 1.4 |
88 |
*/ |
*/ |
89 |
public class LinkedHashMap extends HashMap |
public class LinkedHashMap extends HashMap |
90 |
{ |
{ |
214 |
* Construct a new insertion-ordered LinkedHashMap with a specific |
* Construct a new insertion-ordered LinkedHashMap with a specific |
215 |
* inital capacity and default load factor of 0.75. |
* inital capacity and default load factor of 0.75. |
216 |
* |
* |
217 |
* @param initialCapacity the initial capacity of this HashMap (>=0) |
* @param initialCapacity the initial capacity of this HashMap (>= 0) |
218 |
* @throws IllegalArgumentException if (initialCapacity < 0) |
* @throws IllegalArgumentException if (initialCapacity < 0) |
219 |
*/ |
*/ |
220 |
public LinkedHashMap(int initialCapacity) |
public LinkedHashMap(int initialCapacity) |
221 |
{ |
{ |
227 |
* Construct a new insertion-orderd LinkedHashMap with a specific |
* Construct a new insertion-orderd LinkedHashMap with a specific |
228 |
* inital capacity and load factor. |
* inital capacity and load factor. |
229 |
* |
* |
230 |
* @param initialCapacity the initial capacity (>=0) |
* @param initialCapacity the initial capacity (>= 0) |
231 |
* @param loadFactor the load factor (>0, not NaN) |
* @param loadFactor the load factor (> 0, not NaN) |
232 |
* @throws IllegalArgumentException if (initialCapacity < 0) || |
* @throws IllegalArgumentException if (initialCapacity < 0) || |
233 |
* ! (loadFactor > 0.0) |
* ! (loadFactor > 0.0) |
234 |
*/ |
*/ |
235 |
public LinkedHashMap(int initialCapacity, float loadFactor) |
public LinkedHashMap(int initialCapacity, float loadFactor) |
236 |
{ |
{ |
277 |
LinkedHashEntry e = head; |
LinkedHashEntry e = head; |
278 |
while (e != null) |
while (e != null) |
279 |
{ |
{ |
280 |
if (value == null ? e.value == null : value.equals(e.value)) |
if (equals(value, e.value)) |
281 |
return true; |
return true; |
282 |
e = e.succ; |
e = e.succ; |
283 |
} |
} |
303 |
HashEntry e = buckets[idx]; |
HashEntry e = buckets[idx]; |
304 |
while (e != null) |
while (e != null) |
305 |
{ |
{ |
306 |
if (key == null ? e.key == null : key.equals(e.key)) |
if (equals(key, e.key)) |
307 |
{ |
{ |
308 |
if (accessOrder) |
if (accessOrder) |
309 |
{ |
{ |
372 |
return false; |
return false; |
373 |
} |
} |
374 |
|
|
375 |
/** Helper method called by <code>put</code>, which creates and adds a |
/** |
376 |
|
* Helper method called by <code>put</code>, which creates and adds a |
377 |
* new Entry, followed by performing bookkeeping (like removeEldestEntry). |
* new Entry, followed by performing bookkeeping (like removeEldestEntry). |
378 |
* |
* |
379 |
* @param key the key of the new Entry |
* @param key the key of the new Entry |
380 |
* @param value the value |
* @param value the value |
381 |
* @param idx the index in buckets where the new Entry belongs |
* @param idx the index in buckets where the new Entry belongs |
382 |
* @param callRemove Whether to call the removeEldestEntry method. |
* @param callRemove whether to call the removeEldestEntry method |
383 |
* @see #put(Object, Object) |
* @see #put(Object, Object) |
384 |
* @see #removeEldestEntry(Map.Entry) |
* @see #removeEldestEntry(Map.Entry) |
385 |
*/ |
*/ |
394 |
remove(head); |
remove(head); |
395 |
} |
} |
396 |
|
|
397 |
|
/** |
398 |
|
* Helper method, called by clone() to reset the doubly-linked list. |
399 |
|
* @param m the map to add entries from |
400 |
|
* @see #clone() |
401 |
|
*/ |
402 |
void putAllInternal(Map m) |
void putAllInternal(Map m) |
403 |
{ |
{ |
404 |
head = null; |
head = null; |
468 |
throw new IllegalStateException(); |
throw new IllegalStateException(); |
469 |
|
|
470 |
LinkedHashMap.this.remove(last.key); |
LinkedHashMap.this.remove(last.key); |
|
knownMod++; |
|
471 |
last = null; |
last = null; |
472 |
|
knownMod++; |
473 |
} |
} |
474 |
}; |
}; |
475 |
} |
} |