| java.lang.Object org.apache.commons.collections.map.AbstractMapDecorator org.apache.commons.collections.map.ListOrderedMap
ListOrderedMap | public class ListOrderedMap extends AbstractMapDecorator implements OrderedMap,Serializable(Code) | | 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.
This class is Serializable from Commons Collections 3.1.
since: Commons Collections 3.0 version: $Revision: 365406 $ $Date: 2006-01-02 19:34:53 +0000 (Mon, 02 Jan 2006) $ author: Henri Yandell author: Stephen Colebourne author: Matt Benson |
Inner Class :static class KeySetView extends AbstractSet | |
Inner Class :static class EntrySetView extends AbstractSet | |
Constructor Summary | |
public | ListOrderedMap() Constructs a new empty ListOrderedMap that decorates
a HashMap . | protected | ListOrderedMap(Map map) Constructor that wraps (not copies). |
insertOrder | final protected List insertOrder(Code) | | Internal list to hold the sequence of objects
|
ListOrderedMap | public ListOrderedMap()(Code) | | Constructs a new empty ListOrderedMap that decorates
a HashMap .
since: Commons Collections 3.1 |
ListOrderedMap | protected ListOrderedMap(Map map)(Code) | | Constructor that wraps (not copies).
Parameters: map - the map to decorate, must not be null throws: IllegalArgumentException - if map is null |
asList | public List asList()(Code) | | Gets an unmodifiable List view of the keys which changes as the map changes.
The returned list is unmodifiable because changes to the values of
the list (using
java.util.ListIterator.set(Object) ) will
effectively remove the value from the list and reinsert that value at
the end of the list, which is an unexpected side effect of changing the
value of a list. This occurs because changing the key, changes when the
mapping is added to the map and thus where it appears in the list.
An alternative to this method is to use the better named
ListOrderedMap.keyList() or
ListOrderedMap.keySet() .
See Also: ListOrderedMap.keyList() See Also: ListOrderedMap.keySet() The ordered list of keys. |
clear | public void clear()(Code) | | |
decorate | public static OrderedMap decorate(Map map)(Code) | | Factory method to create an ordered map.
An ArrayList is used to retain order.
Parameters: map - the map to decorate, must not be null throws: IllegalArgumentException - if map is null |
entrySet | public Set entrySet()(Code) | | Gets a view over the entries in the map.
The Set will be ordered by object insertion into the map.
the fully modifiable set view over the entries |
firstKey | public Object firstKey()(Code) | | Gets the first key in this map by insert order.
the first key currently in this map throws: NoSuchElementException - if this map is empty |
get | public Object get(int index)(Code) | | Gets the key at the specified index.
Parameters: index - the index to retrieve the key at the specified index throws: IndexOutOfBoundsException - if the index is invalid |
getValue | public Object getValue(int index)(Code) | | Gets the value at the specified index.
Parameters: index - the index to retrieve the key at the specified index throws: IndexOutOfBoundsException - if the index is invalid |
indexOf | public int indexOf(Object key)(Code) | | Gets the index of the specified key.
Parameters: key - the key to find the index of the index, or -1 if not found |
keyList | public List keyList()(Code) | | Gets a view over the keys in the map as a List.
The List will be ordered by object insertion into the map.
The List is unmodifiable.
See Also: ListOrderedMap.keySet() the unmodifiable list view over the keys since: Commons Collections 3.2 |
keySet | public Set keySet()(Code) | | Gets a view over the keys in the map.
The Collection will be ordered by object insertion into the map.
See Also: ListOrderedMap.keyList() the fully modifiable collection view over the keys |
lastKey | public Object lastKey()(Code) | | Gets the last key in this map by insert order.
the last key currently in this map throws: NoSuchElementException - if this map is empty |
nextKey | public Object nextKey(Object key)(Code) | | Gets the next key to the one specified using insert order.
This method performs a list search to find the key and is O(n).
Parameters: key - the key to find previous for the next key, null if no match or at start |
previousKey | public Object previousKey(Object key)(Code) | | Gets the previous key to the one specified using insert order.
This method performs a list search to find the key and is O(n).
Parameters: key - the key to find previous for the previous key, null if no match or at start |
put | public Object put(int index, Object key, Object value)(Code) | | Puts a key-value mapping into the map at the specified index.
If the map already contains the key, then the original mapping
is removed and the new mapping added at the specified index.
The remove may change the effect of the index. The index is
always calculated relative to the original state of the map.
Thus the steps are: (1) remove the existing key-value mapping,
then (2) insert the new key-value mapping at the position it
would have been inserted had the remove not ocurred.
Parameters: index - the index at which the mapping should be inserted Parameters: key - the key Parameters: value - the value the value previously mapped to the key throws: IndexOutOfBoundsException - if the index is out of range since: Commons Collections 3.2 |
remove | public Object remove(int index)(Code) | | Removes the element at the specified index.
Parameters: index - the index of the object to remove the removed value, or null if none existed throws: IndexOutOfBoundsException - if the index is invalid |
setValue | public Object setValue(int index, Object value)(Code) | | Sets the value at the specified index.
Parameters: index - the index of the value to set the previous value at that index throws: IndexOutOfBoundsException - if the index is invalid since: Commons Collections 3.2 |
toString | public String toString()(Code) | | Returns the Map as a string.
the Map as a String |
valueList | public List valueList()(Code) | | Gets a view over the values in the map as a List.
The List will be ordered by object insertion into the map.
The List supports remove and set, but does not support add.
See Also: ListOrderedMap.values() the partially modifiable list view over the values since: Commons Collections 3.2 |
Fields inherited from org.apache.commons.collections.map.AbstractMapDecorator | protected transient Map map(Code)(Java Doc)
|
|
|