Decorates a
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 {@link java.util.Collections#synchronizedMap(Map)}. This class may throw exceptions when accessed by concurrent threads without synchronization.
Note that ListOrderedMap doesn't work with {@link java.util.IdentityHashMap IdentityHashMap}, {@link CaseInsensitiveMap}, or similar maps that violate the general contract of {@link java.util.Map}. The ListOrderedMap
(or, more precisely, the underlying List
) is relying on {@link Object#equals(Object) equals()}. This is fine, as long as the decorated Map
is also based on {@link Object#equals(Object) equals()}, and {@link Object#hashCode() hashCode()}, which {@link java.util.IdentityHashMap IdentityHashMap}, and {@link CaseInsensitiveMap} don't: The former uses ==
, andthe latter uses {@link Object#equals(Object) equals()} on a lower-casedkey.
This class is {@link Serializable} starting with Commons Collections 3.1.
@since 3.0
@version $Id: ListOrderedMap.java 1496190 2013-06-24 20:04:16Z tn $