public class LinkedMap extends AbstractLinkedMap implements java.io.Serializable, java.lang.Cloneable
Map
implementation that maintains the order of the entries.
In this implementation order is maintained by original insertion.
This implementation improves on the JDK1.4 LinkedHashMap by adding the
MapIterator
functionality, additional convenience methods and allowing
bidirectional iteration. It also implements OrderedMap
.
In addition, non-interface methods are provided to access the map by index.
The orderedMapIterator()
method provides direct access to a
bidirectional iterator. The iterators from the other views can also be cast
to OrderedIterator
if required.
All the available iterators can be reset back to the start by casting to
ResettableIterator
and calling reset()
.
The implementation is also designed to be subclassed, with lots of useful methods exposed.
Note that LinkedMap 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 Collections.synchronizedMap(Map)
. This class may throw
exceptions when accessed by concurrent threads without synchronization.
Constructor and Description |
---|
LinkedMap()
Constructs a new empty map with default size and load factor.
|
LinkedMap(int initialCapacity)
Constructs a new, empty map with the specified initial capacity.
|
LinkedMap(int initialCapacity,
float loadFactor)
Constructs a new, empty map with the specified initial capacity and
load factor.
|
LinkedMap(java.util.Map map)
Constructor copying elements from another map.
|
Modifier and Type | Method and Description |
---|---|
java.util.List |
asList()
Gets an unmodifiable List view of the keys.
|
java.lang.Object |
clone()
Clones the map without cloning the keys or values.
|
java.lang.Object |
get(int index)
Gets the key at the specified index.
|
java.lang.Object |
getValue(int index)
Gets the value at the specified index.
|
int |
indexOf(java.lang.Object key)
Gets the index of the specified key.
|
java.lang.Object |
remove(int index)
Removes the element at the specified index.
|
clear, containsValue, firstKey, lastKey, mapIterator, nextKey, orderedMapIterator, previousKey
public LinkedMap()
public LinkedMap(int initialCapacity)
initialCapacity
- the initial capacityjava.lang.IllegalArgumentException
- if the initial capacity is less than onepublic LinkedMap(int initialCapacity, float loadFactor)
initialCapacity
- the initial capacityloadFactor
- the load factorjava.lang.IllegalArgumentException
- if the initial capacity is less than onejava.lang.IllegalArgumentException
- if the load factor is less than zeropublic LinkedMap(java.util.Map map)
map
- the map to copyjava.lang.NullPointerException
- if the map is nullpublic java.lang.Object clone()
public java.lang.Object get(int index)
index
- the index to retrievejava.lang.IndexOutOfBoundsException
- if the index is invalidpublic java.lang.Object getValue(int index)
index
- the index to retrievejava.lang.IndexOutOfBoundsException
- if the index is invalidpublic int indexOf(java.lang.Object key)
key
- the key to find the index ofpublic java.lang.Object remove(int index)
index
- the index of the object to removekey
,
or null
if none existedjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic java.util.List asList()
The returned list is unmodifiable because changes to the values of
the list (using 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 AbstractHashedMap.keySet()
.
AbstractHashedMap.keySet()
Copyright © 2010 - 2020 Adobe. All Rights Reserved