This implementation is needed to address the lack of function needed by us: replaceAtIndexOf.
The java. keeps the order of insertion, but has no possibility to replace an item at given index,
so if you want to keep the insertion order with a possibility to swap at some particular index, you need such implementation.
The implementation is based on a simple ArrayList. Each get, containsKey etc. call
traverses the array map, therefore it is not an optimal data structure if random lookups are performed often.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv class |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final ArrayList | |
| private final Map. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | clear()
Overrides java. Implements java. Removes all of the mappings from this map (optional operation). |
| public boolean | containsValue(Object value)
Overrides java. Implements java. Returns |
| public Set | entrySet()
Implements abstract java. Implements java. Returns a |
| public V | get(Object key)
Overrides java. Implements java. Returns the value to which the specified key is mapped,
or |
| public Set | keySet()
Overrides java. Implements java. Returns a |
| public V | put(K key, V value)
Overrides java. Implements java. Associates the specified value with the specified key in this map (optional operation). |
| public V | remove(Object key)
Overrides java. Implements java. Removes the mapping for a key from this map if it is present (optional operation). |
| public void | replaceAtIndexOf(K oldKey, K newKey, V value)
Replaces entry at the index of |
| public int | size()
Overrides java. Implements java. Returns the number of key-value mappings in this map. |
| public Collection | values()
Overrides java. Implements java. Returns a |
| entries | back to summary |
|---|---|
| pack-priv final ArrayList<Map. | |
| nullValue | back to summary |
|---|---|
| private final Map. | |
| IndexedMap | back to summary |
|---|---|
| pack-priv IndexedMap() | |
| clear | back to summary |
|---|---|
| public void clear() Overrides java. Implements java. Doc from java. Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.
| |
| containsValue | back to summary |
|---|---|
| public boolean containsValue(Object value) Overrides java. Implements java. Doc from java. Returns
| |
| entrySet | back to summary |
|---|---|
| public Set Implements abstract java. Implements java. Doc from java. Returns a
| |
| get | back to summary |
|---|---|
| public V get(Object key) Overrides java. Implements java. Doc from java. Returns the value to which the specified key is mapped,
or More formally, if this map contains a mapping from a key
If this map permits null values, then a return value of
| |
| keySet | back to summary |
|---|---|
| public Set Overrides java. Implements java. Doc from java. Returns a
| |
| put | back to summary |
|---|---|
| public V put(K key, V value) Overrides java. Implements java. Doc from java. Associates the specified value with the specified key in this map
(optional operation). If the map previously contained a mapping for
the key, the old value is replaced by the specified value. (A map
| |
| remove | back to summary |
|---|---|
| public V remove(Object key) Overrides java. Implements java. Doc from java. Removes the mapping for a key from this map if it is present
(optional operation). More formally, if this map contains a mapping
from key Returns the value to which this map previously associated the key,
or If this map permits null values, then a return value of
The map will not contain a mapping for the specified key once the call returns.
| |
| replaceAtIndexOf | back to summary |
|---|---|
| public void replaceAtIndexOf(K oldKey, K newKey, V value) Replaces entry at the index of | |
| size | back to summary |
|---|---|
| public int size() Overrides java. Implements java. Doc from java. Returns the number of key-value mappings in this map. If the
map contains more than
| |
| values | back to summary |
|---|---|
| public Collection Overrides java. Implements java. Doc from java. Returns a
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | clear()
Overrides java. Implements java. Removes all of the elements from this list (optional operation). |
| public boolean | contains(Object o)
Overrides java. Implements java. Returns |
| public V | get(int index)
Implements abstract java. Implements java. Returns the element at the specified position in this list. |
| public Iterator | iterator()
Overrides java. Implements java. Returns an iterator over the elements in this list in proper sequence. |
| public boolean | remove(Object o)
Overrides java. Implements java. Removes the first occurrence of the specified element from this list, if it is present (optional operation). |
| public int | size()
Implements abstract java. Implements java. Returns the number of elements in this list. |
| public Object[] | toArray()
Overrides java. Implements java. Returns an array containing all of the elements in this list in proper sequence (from first to last element). |
| public <T> T[] | toArray(T[] a)
Overrides java. Implements java. Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. |
| Values | back to summary |
|---|---|
| pack-priv Values() | |
| clear | back to summary |
|---|---|
| public void clear() Overrides java. Implements java. Doc from java. Removes all of the elements from this list (optional operation). The list will be empty after this call returns.
| |
| contains | back to summary |
|---|---|
| public boolean contains(Object o) Overrides java. Implements java. Doc from java. Returns
| |
| get | back to summary |
|---|---|
| public V get(int index) Implements abstract java. Implements java. Doc from java. Returns the element at the specified position in this list.
| |
| iterator | back to summary |
|---|---|
| public Iterator Overrides java. Implements java. Doc from java. Returns an iterator over the elements in this list in proper sequence.
| |
| remove | back to summary |
|---|---|
| public boolean remove(Object o) Overrides java. Implements java. Doc from java. Removes the first occurrence of the specified element from this list,
if it is present (optional operation). If this list does not contain
the element, it is unchanged. More formally, removes the element with
the lowest index
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this list. If this list contains
more than
| |
| toArray | back to summary |
|---|---|
| public Object[] toArray() Overrides java. Implements java. Doc from java. Returns an array containing all of the elements in this list in proper sequence (from first to last element). The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify the returned array. This method acts as bridge between array-based and collection-based APIs.
| |
| toArray | back to summary |
|---|---|
| public <T> T[] toArray(T[] a) Overrides java. Implements java. Doc from java. Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list. If the list fits in the specified array with room to spare (i.e.,
the array has more elements than the list), the element in the array
immediately following the end of the list is set to Like the Suppose
Note that toArray(new Object[0]) is identical in function to
toArray().
| |