Top Description Inners Fields Constructors Methods
org.apache.commons.collections4.map

public Class ListOrderedMap<K, V>

extends AbstractMapDecorator<K, V>
implements OrderedMap<K, V>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.collections4.OrderedMap, org.apache.commons.collections4.IterableMap, org.apache.commons.collections4.IterableGet, org.apache.commons.collections4.Get, org.apache.commons.collections4.Put, java.util.Map
Type Parameters
<K>
the type of the keys in this map
<V>
the type of the values in this map
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serializable, java.util.AbstractList, .AbstractSet, .ArrayList, .Collection, .HashMap, .Iterator, .List, .ListIterator, .Map, .NoSuchElementException, .Set, org.apache.commons.collections4.OrderedMap, .OrderedMapIterator, .ResettableIterator, org.apache.commons.collections4.iterators.AbstractUntypedIteratorDecorator, org.apache.commons.collections4.keyvalue.AbstractMapEntry, org.apache.commons.collections4.list.UnmodifiableList

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 java.util.Collections#synchronizedMap(Map). 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.util.Map. 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.

Since
3.0

Nested and Inner Type Summary

Modifier and TypeClass 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

Field Summary

Modifier and TypeField and Description
private final List<K>
insertOrder

Internal list to hold the sequence of objects

private static final long
serialVersionUID

Serialization version

Inherited from org.apache.commons.collections4.map.AbstractMapDecorator:
map

Constructor Summary

AccessConstructor and Description
public
ListOrderedMap()

Constructs a new empty ListOrderedMap that decorates a HashMap.

protected
ListOrderedMap(final Map<K, V>
the map to decorate, must not be null
map
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public List<K>

Returns:

The ordered list of keys.
asList
()

Gets an unmodifiable List view of the keys which changes as the map changes.

public void
clear()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.clear.

Implements java.util.Map.clear, org.apache.commons.collections4.Put.clear.

Removes all of the mappings from this map (optional operation).
public Set<Map.Entry<K, V>>

Returns:

the fully modifiable set view over the entries
entrySet
()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.entrySet.

Implements java.util.Map.entrySet, org.apache.commons.collections4.Get.entrySet.

Gets a view over the entries in the map.
public K

Returns:

the first key currently in this map
firstKey
()

Implements org.apache.commons.collections4.OrderedMap.firstKey.

Gets the first key in this map by insert order.
public K

Returns:

the key at the specified index
get
(final int
the index to retrieve
index
)

Gets the key at the specified index.

public V

Returns:

the key at the specified index
getValue
(final int
the index to retrieve
index
)

Gets the value at the specified index.

public int

Returns:

the index, or -1 if not found
indexOf
(final Object
the key to find the index of
key
)

Gets the index of the specified key.

public List<K>

Returns:

the unmodifiable list view over the keys
keyList
()

Gets a view over the keys in the map as a List.

public Set<K>

Returns:

the fully modifiable collection view over the keys
keySet
()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.keySet.

Implements java.util.Map.keySet, org.apache.commons.collections4.Get.keySet.

Gets a view over the keys in the map.
public K

Returns:

the last key currently in this map
lastKey
()

Implements org.apache.commons.collections4.OrderedMap.lastKey.

Gets the last key in this map by insert order.
public static <
the key type
K
,
the value type
V
>
ListOrderedMap<K, V>

Returns:

a new list ordered map
listOrderedMap
(final Map<K, V>
the map to decorate, must not be null
map
)

Factory method to create an ordered map.

public OrderedMapIterator<K, V>
public K

Returns:

the next key, null if no match or at start
nextKey
(final Object
the key to find previous for
key
)

Implements org.apache.commons.collections4.OrderedMap.nextKey.

Gets the next key to the one specified using insert order.
public K

Returns:

the previous key, null if no match or at start
previousKey
(final Object
the key to find previous for
key
)

Implements org.apache.commons.collections4.OrderedMap.previousKey.

Gets the previous key to the one specified using insert order.
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.apache.commons.collections4.map.AbstractMapDecorator.put.

Implements java.util.Map.put, org.apache.commons.collections4.Put.put.

Associates the specified value with the specified key in this map (optional operation).
public V

Returns:

the value previously mapped to the key
put
(int
the 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.apache.commons.collections4.map.AbstractMapDecorator.putAll.

Implements java.util.Map.putAll, org.apache.commons.collections4.Put.putAll.

Copies all of the mappings from the specified map to this map (optional operation).
public void
putAll(int
the index in the Map to start at.
index
,
final Map<? extends K, ? extends V>
the Map containing the entries to be added.
map
)

Puts the values contained in a supplied Map into the Map starting at the specified index.

private void
readObject(final ObjectInputStream
the input stream
in
)

Read the map in using a custom routine.

public V
remove(final Object
key whose mapping is to be removed from the map
key
)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.remove.

Implements java.util.Map.remove, org.apache.commons.collections4.Get.remove.

Removes the mapping for a key from this map if it is present (optional operation).
public V

Returns:

the removed value, or null if none existed
remove
(final int
the index of the object to remove
index
)

Removes the element at the specified index.

public V

Returns:

the previous value at that index
setValue
(final int
the 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 String
toString
()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.toString.

Returns the Map as a string.
public List<V>

Returns:

the partially modifiable list view over the values
valueList
()

Gets a view over the values in the map as a List.

public Collection<V>

Returns:

the fully modifiable collection view over the values
values
()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.values.

Implements java.util.Map.values, org.apache.commons.collections4.Get.values.

Gets a view over the values in the map.
private void
writeObject(final ObjectOutputStream
the output stream
out
)

Write the map out using a custom routine.

Inherited from org.apache.commons.collections4.map.AbstractMapDecorator:
containsKeycontainsValuedecoratedequalsgethashCodeisEmptysize