Map to ensure that the order of addition is retained
using a List to maintain order.
The order will be used via the iterators and toArray methods on the views.
The order is also returned by the MapIterator.
The orderedMapIterator() method accesses an iterator that can
iterate both forwards and backwards through the map.
In addition, non-interface methods are provided to access the map by index.
If an object is added to the Map for a second time, it will remain in the original position in the iteration.
Note that ListOrderedMap is not synchronized and is not thread-safe.
If you wish to use this map from multiple threads concurrently, you must use
appropriate synchronization. The simplest approach is to wrap this map
using java.. This class may throw
exceptions when accessed by concurrent threads without synchronization.
Note that ListOrderedMap doesn't work with
IdentityHashMap, CaseInsensitiveMap,
or similar maps that violate the general contract of java..
The ListOrderedMap (or, more precisely, the underlying List)
is relying on equals(). This is fine, as long as the
decorated Map is also based on equals(),
and hashCode(), which
IdentityHashMap, and
CaseInsensitiveMap don't: The former uses ==, and
the latter uses equals() on a lower-cased
key.
This class is Serializable starting with Commons Collections 3.1.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private final List | insertOrder
Internal list to hold the sequence of objects |
| private static final long | serialVersionUID
Serialization version |
| Access | Constructor and Description |
|---|---|
| public | |
| protected | ListOrderedMap(final Map<K, V>
the map to decorate, must not be null map)Constructor that wraps (not copies). |
| Modifier and Type | Method and Description |
|---|---|
| public List | Returns: The ordered list of keys.Gets an unmodifiable List view of the keys which changes as the map changes. |
| public void | clear()
Overrides org. Implements java. |
| public Set | Returns: the fully modifiable set view over the entriesOverrides org. Implements java. |
| public K | Returns: the first key currently in this mapImplements org. |
| public K | Returns: the key at the specified indexthe index to retrieve index)Gets the key at the specified index. |
| public V | Returns: the key at the specified indexthe index to retrieve index)Gets the value at the specified index. |
| public int | |
| public List | Returns: the unmodifiable list view over the keysGets a view over the keys in the map as a List. |
| public Set | Returns: the fully modifiable collection view over the keysOverrides org. Implements java. |
| public K | Returns: the last key currently in this mapImplements org. |
| public static < the key type K, the value type V> ListOrderedMap | Returns: a new list ordered mapthe map to decorate, must not be null map)Factory method to create an ordered map. |
| public OrderedMapIterator | mapIterator()
Overrides org. Implements org. OrderedMapIterator over the map.
|
| public K | Returns: the next key, null if no match or at startthe key to find previous for key)Implements org. |
| public K | Returns: the previous key, null if no match or at startthe key to find previous for key)Implements org. |
| public V | put(final K
key with which the specified value is to be associated key, final V value to be associated with the specified key value)Overrides org. Implements java. |
| public V | Returns: the value previously mapped to the keythe index at which the mapping should be inserted index, final K the key key, final V the value value)Puts a key-value mapping into the map at the specified index. |
| public void | putAll(final Map<? extends K, ? extends V>
mappings to be stored in this map map)Overrides org. Implements java. |
| public void | |
| private void | |
| public V | remove(final Object
key whose mapping is to be removed from the map key)Overrides org. Implements java. |
| public V | Returns: the removed value, ornull if none existedthe index of the object to remove index)Removes the element at the specified index. |
| public V | Returns: the previous value at that indexthe index of the value to set index, final V the new value to set value)Sets the value at the specified index. |
| public String | Returns: the Map as a StringOverrides org. |
| public List | Returns: the partially modifiable list view over the valuesGets a view over the values in the map as a List. |
| public Collection | Returns: the fully modifiable collection view over the valuesOverrides org. Implements java. |
| private void |