Build 1.0_r1(from source)

java.util
Class LinkedHashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>
Direct Known Subclasses:
NegativeCache

public class LinkedHashMap<K,V>
extends HashMap<K,V>

LinkedHashMap is a variant on HashMap. Its entries are kept in a doubly-linked list. The iteration order is, by default, the order in which keys were inserted.

If the three argument constructor is used, and order is specified as true, the iteration would be in the order that entries were accessed. The access order gets affected by put(), get(), putAll() operations, but not by operations on the collection views.

Null elements are allowed, and all the optional Map operations are supported.

Since:
1.4
See Also:
Serialized Form

Nested Class Summary
(package private) static class LinkedHashMap.LinkedHashIterator<E,KT,VT>
           
(package private) static class LinkedHashMap.LinkedHashMapEntry<K,V>
           
(package private) static class LinkedHashMap.LinkedHashMapEntrySet<KT,VT>
           
 
Nested classes/interfaces inherited from class java.util.HashMap
HashMap.Entry<K,V>, HashMap.HashMapEntrySet<KT,VT>, HashMap.HashMapIterator<E,KT,VT>
 
Field Summary
 
Fields inherited from class java.util.HashMap
elementCount, elementData, loadFactor, modCount, threshold
 
Fields inherited from class java.util.AbstractMap
keySet, valuesCollection
 
Constructor Summary
LinkedHashMap()
          Constructs a new empty instance of LinkedHashMap.
LinkedHashMap(int s)
          Constructor with specified size.
LinkedHashMap(int s, float lf)
          Constructor with specified size and load factor.
LinkedHashMap(int s, float lf, boolean order)
          Constructor with specified size, load factor and access order
LinkedHashMap(Map<? extends K,? extends V> m)
          Constructor with input map
 
Method Summary
 void clear()
          Removes all mappings from this HashMap, leaving it empty.
(package private)  HashMap.Entry<K,V> createEntry(K key, int index, V value)
           
(package private)  HashMap.Entry<K,V> createHashedEntry(K key, int index, int hash)
           
 Set<Map.Entry<K,V>> entrySet()
          Returns a Set of the mappings contained in this HashMap.
 V get(Object key)
          Retrieve the map value corresponding to the given key.
 Set<K> keySet()
          Returns a Set of the keys contained in this HashMap.
(package private)  void linkEntry(LinkedHashMap.LinkedHashMapEntry<K,V> m)
           
(package private)  HashMap.Entry<K,V>[] newElementArray(int s)
          Create a new element array
 V put(K key, V value)
          Set the mapped value for the given key to the given value.
(package private)  V putImpl(K key, V value)
           
 V remove(Object key)
          Remove the entry corresponding to the given key.
protected  boolean removeEldestEntry(Map.Entry<K,V> eldest)
          This method is queried from the put and putAll methods to check if the eldest member of the map should be deleted before adding the new member.
 Collection<V> values()
          Returns a Collection of the values contained in this HashMap.
 
Methods inherited from class java.util.HashMap
clone, containsKey, containsValue, findNonNullKeyEntry, findNullKeyEntry, isEmpty, putAll, rehash, rehash, removeEntry, size
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

LinkedHashMap

public LinkedHashMap()
Constructs a new empty instance of LinkedHashMap.


LinkedHashMap

public LinkedHashMap(int s)
Constructor with specified size.

Parameters:
s - Size of LinkedHashMap required

LinkedHashMap

public LinkedHashMap(int s,
                     float lf)
Constructor with specified size and load factor.

Parameters:
s - Size of LinkedHashMap required
lf - Load factor

LinkedHashMap

public LinkedHashMap(int s,
                     float lf,
                     boolean order)
Constructor with specified size, load factor and access order

Parameters:
s - Size of LinkedHashmap required
lf - Load factor
order - If true indicates that traversal order should begin with most recently accessed

LinkedHashMap

public LinkedHashMap(Map<? extends K,? extends V> m)
Constructor with input map

Parameters:
m - Input map
Method Detail

newElementArray

HashMap.Entry<K,V>[] newElementArray(int s)
Create a new element array

Overrides:
newElementArray in class HashMap<K,V>
Parameters:
s -
Returns:
Reference to the element array

get

public V get(Object key)
Retrieve the map value corresponding to the given key.

Specified by:
get in interface Map<K,V>
Overrides:
get in class HashMap<K,V>
Parameters:
key - Key value
Returns:
mapped value or null if the key is not in the map

createEntry

HashMap.Entry<K,V> createEntry(K key,
                               int index,
                               V value)
Overrides:
createEntry in class HashMap<K,V>

createHashedEntry

HashMap.Entry<K,V> createHashedEntry(K key,
                                     int index,
                                     int hash)
Overrides:
createHashedEntry in class HashMap<K,V>

put

public V put(K key,
             V value)
Set the mapped value for the given key to the given value.

Specified by:
put in interface Map<K,V>
Overrides:
put in class HashMap<K,V>
Parameters:
key - Key value
value - New mapped value
Returns:
The old value if the key was already in the map or null otherwise.

putImpl

V putImpl(K key,
          V value)
Overrides:
putImpl in class HashMap<K,V>

linkEntry

void linkEntry(LinkedHashMap.LinkedHashMapEntry<K,V> m)

entrySet

public Set<Map.Entry<K,V>> entrySet()
Returns a Set of the mappings contained in this HashMap. Each element in the set is a Map.Entry. The set is backed by this HashMap so changes to one are reflected by the other. The set does not support adding.

Specified by:
entrySet in interface Map<K,V>
Overrides:
entrySet in class HashMap<K,V>
Returns:
a Set of the mappings

keySet

public Set<K> keySet()
Returns a Set of the keys contained in this HashMap. The set is backed by this HashMap so changes to one are reflected by the other. The set does not support adding.

Specified by:
keySet in interface Map<K,V>
Overrides:
keySet in class HashMap<K,V>
Returns:
a Set of the keys

values

public Collection<V> values()
Returns a Collection of the values contained in this HashMap. The collection is backed by this HashMap so changes to one are reflected by the other. The collection does not support adding.

Specified by:
values in interface Map<K,V>
Overrides:
values in class HashMap<K,V>
Returns:
a Collection of the values

remove

public V remove(Object key)
Remove the entry corresponding to the given key.

Specified by:
remove in interface Map<K,V>
Overrides:
remove in class HashMap<K,V>
Parameters:
key - the key
Returns:
the value associated with the key or null if the key was no in the map

removeEldestEntry

protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
This method is queried from the put and putAll methods to check if the eldest member of the map should be deleted before adding the new member. If this map was created with accessOrder = true, then the result of removeEldesrEntry is assumed to be false.

Parameters:
eldest -
Returns:
true if the eldest member should be removed

clear

public void clear()
Removes all mappings from this HashMap, leaving it empty.

Specified by:
clear in interface Map<K,V>
Overrides:
clear in class HashMap<K,V>
See Also:
HashMap.isEmpty(), HashMap.size()

Build 1.0_r1(from source)

Please submit a feedback, bug or feature