public class IndexMap<K,V>
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
| Modifier and Type | Class and Description |
|---|---|
static class |
IndexMap.ListIndexMap<K,V>
Provide access to the index map via list interface.
|
static class |
IndexMap.MapIndexMap<K,V>
Provide access to the index map via map interface.
|
| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<V> |
aslist
The index map as java.util.List.
|
protected java.util.Map<K,V> |
asmap
The index map as java.util.Map.
|
protected java.util.List<K> |
list
The key list.
|
protected java.util.Map<K,V> |
map
The key/value map.
|
| Constructor and Description |
|---|
IndexMap()
Create a new index map.
|
IndexMap(IndexMap<K,V> imap)
Create a new index map.
|
IndexMap(java.util.List<K> list,
java.util.Map<K,V> map)
Create a new index map using the specified collections as backup.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index,
K key,
V o)
Add an object to the collection.
|
void |
add(int index,
java.lang.Object element)
Unsupported method, due to missing key parameter.
|
void |
add(K key,
V o)
Add a new object with key and value.
|
boolean |
add(java.lang.Object o)
Unsupported method, due to missing key parameter.
|
boolean |
addAll(java.util.Collection c)
Unsupported method, due to missing key parameter.
|
boolean |
addAll(int index,
java.util.Collection c)
Unsupported method, due to missing key parameter.
|
void |
clear()
Removes all mappings from this map.
|
java.lang.Object |
clone()
Clone an index map.
|
boolean |
contains(java.lang.Object o)
Returns
|
boolean |
containsAll(java.util.Collection<?> c)
Returns
|
boolean |
containsKey(java.lang.Object key)
Returns
|
boolean |
containsValue(java.lang.Object value)
Returns
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
Returns a set view of the mappings contained in this map.
|
boolean |
equals(java.lang.Object o)
Compares the specified object with this map for equality.
|
V |
get(int index)
Returns the element at the specified position in this list.
|
V |
get(java.lang.Object key)
Returns the value to which this map maps the specified key.
|
java.util.List<V> |
getAsList()
Return an instance of this index map accessible via list interface.
|
java.util.Map<K,V> |
getAsMap()
Return an instance of this index map accessible via map interface.
|
K |
getKey(int index)
Get an indexed key.
|
java.lang.Object[] |
getKeys()
Get the keys as array.
|
java.lang.Object[] |
getKeys(java.lang.Class<?> type)
Get the keys as array.
|
java.lang.Object[] |
getObjects()
Get the values as array.
|
java.lang.Object[] |
getObjects(java.lang.Class type)
Get the values as array.
|
int |
hashCode()
Returns the hash code value for this map.
|
int |
indexOf(java.lang.Object o)
Returns the index in this list of the first occurrence of the specified
element, or -1 if this list does not contain this element.
|
boolean |
isEmpty()
Returns
|
java.util.Iterator<V> |
iterator()
Returns an iterator over the elements in this list in proper sequence.
|
java.util.Set<K> |
keySet()
Returns a set view of the keys contained in this map.
|
int |
lastIndexOf(java.lang.Object o)
Returns the index in this list of the last occurrence of the specified
element, or -1 if this list does not contain this element.
|
java.util.ListIterator<V> |
listIterator()
Returns a list iterator of the elements in this list (in proper
sequence).
|
java.util.ListIterator<V> |
listIterator(int index)
Returns a list iterator of the elements in this list (in proper
sequence), starting at the specified position in this list.
|
V |
put(K key,
V value)
Associates the specified value with the specified key in this map
(optional operation).
|
void |
putAll(java.util.Map<? extends K,? extends V> t)
Copies all of the mappings from the specified map to this map
(optional operation).
|
V |
remove(int index)
Removes the element at the specified position in this list.
|
boolean |
removeAll(java.util.Collection<?> c)
Removes from this list all the elements that are contained in the
specified collection.
|
V |
removeKey(K key)
Removes the mapping for this key from this map if it is present.
|
boolean |
removeValue(java.lang.Object o)
Removes the first occurrence in this list of the specified element.
|
V |
replace(K key,
V o)
Replace an object for the given key.
|
boolean |
retainAll(java.util.Collection<?> c)
Retains only the elements in this list that are contained in the
specified collection.
|
V |
set(int index,
V element)
Replaces the element at the specified position in this list with the
specified element.
|
int |
size()
Returns the number of key-value mappings in this map.
|
java.util.List |
subList(int fromIndex,
int toIndex)
Unsupported method.
|
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this list in proper
sequence.
|
<T> T[] |
toArray(T[] array)
Returns an array containing all of the elements in this list in proper
sequence; the runtime type of the returned array is that of the
specified array.
|
java.lang.String |
toString()
Create a string representation of this map.
|
java.util.Collection<V> |
values()
Returns a collection view of the values contained in this map.
|
protected java.util.List<K> list
protected java.util.List<V> aslist
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
clone in class java.lang.Objectjava.lang.CloneNotSupportedExceptionpublic int size()
public boolean isEmpty()
public boolean containsKey(java.lang.Object key)
key - key whose presence in this map is to be tested.java.lang.ClassCastException - if the key is of an inappropriate type for
this map (optional).java.lang.NullPointerException - if the key is
public boolean containsValue(java.lang.Object value)
value - value whose presence in this map is to be tested.java.lang.ClassCastException - if the value is of an inappropriate type for
this map (optional).java.lang.NullPointerException - if the value is
public V get(java.lang.Object key)
key - key whose associated value is to be returned.java.lang.ClassCastException - if the key is of an inappropriate type for
this map (optional).java.lang.NullPointerException - key is
containsKey(Object)public V put(K key, V value)
m.containsKey(k) would return
key - key with which the specified value is to be associated.value - value to be associated with the specified key.java.lang.UnsupportedOperationException - if the
java.lang.ClassCastException - if the class of the specified key or value
prevents it from being stored in this map.java.lang.IllegalArgumentException - if some aspect of this key or value
prevents it from being stored in this map.java.lang.NullPointerException - this map does not permit
public void putAll(java.util.Map<? extends K,? extends V> t)
put(k, v) on this map once
for each mapping from key
t - Mappings to be stored in this map.java.lang.UnsupportedOperationException - if the
java.lang.ClassCastException - if the class of a key or value in the
specified map prevents it from being stored in this map.java.lang.IllegalArgumentException - some aspect of a key or value in the
specified map prevents it from being stored in this map.java.lang.NullPointerException - the specified map is
public void clear()
public java.util.Set<K> keySet()
public java.util.Collection<V> values()
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
public boolean equals(java.lang.Object o)
equals in class java.lang.Objecto - object to be compared for equality with this map.public int hashCode()
hashCode in class java.lang.ObjectObject.hashCode(),
Object.equals(Object),
equals(Object)public java.lang.String toString()
toString in class java.lang.Objectpublic boolean contains(java.lang.Object o)
o - element whose presence in this list is to be tested.java.lang.ClassCastException - if the type of the specified element
is incompatible with this list (optional).java.lang.NullPointerException - if the specified element is null and this
list does not support null elements (optional).public java.util.Iterator<V> iterator()
public java.lang.Object[] toArray()
Arrays.asList(Object[])public <T> T[] toArray(T[] array)
array - the array into which the elements of this list are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.java.lang.ArrayStoreException - if the runtime type of the specified array
is not a supertype of the runtime type of every element in
this list.java.lang.NullPointerException - if the specified array is
public boolean containsAll(java.util.Collection<?> c)
c - collection to be checked for containment in this list.java.lang.ClassCastException - if the types of one or more elements
in the specified collection are incompatible with this
list (optional).java.lang.NullPointerException - if the specified collection contains one
or more null elements and this list does not support null
elements (optional).java.lang.NullPointerException - if the specified collection is
contains(Object)public boolean removeAll(java.util.Collection<?> c)
c - collection that defines which elements will be removed from
this list.java.lang.ClassCastException - if the types of one or more elements
in this list are incompatible with the specified
collection (optional).java.lang.NullPointerException - if this list contains one or more
null elements and the specified collection does not support
null elements (optional).java.lang.NullPointerException - if the specified collection is
removeValue(Object),
contains(Object)public boolean retainAll(java.util.Collection<?> c)
c - collection that defines which elements this set will retain.java.lang.ClassCastException - if the types of one or more elements
in this list are incompatible with the specified
collection (optional).java.lang.NullPointerException - if this list contains one or more
null elements and the specified collection does not support
null elements (optional).java.lang.NullPointerException - if the specified collection is
removeValue(Object),
contains(Object)public V get(int index)
index - index of element to return.java.lang.IndexOutOfBoundsException - if the index is out of range (index
< 0 || index >= size()).public V set(int index, V element)
index - index of element to replace.element - element to be stored at the specified position.java.lang.ClassCastException - if the class of the specified element
prevents it from being added to this list.java.lang.NullPointerException - if the specified element is null and
this list does not support null elements.java.lang.IllegalArgumentException - if some aspect of the specified
element prevents it from being added to this list.java.lang.IndexOutOfBoundsException - if the index is out of range
(index < 0 || index >= size()).public V remove(int index)
index - the index of the element to removed.java.lang.IndexOutOfBoundsException - if the index is out of range (index
< 0 || index >= size()).public int indexOf(java.lang.Object o)
o - element to search for.java.lang.ClassCastException - if the type of the specified element
is incompatible with this list (optional).java.lang.NullPointerException - if the specified element is null and this
list does not support null elements (optional).public int lastIndexOf(java.lang.Object o)
o - element to search for.java.lang.ClassCastException - if the type of the specified element
is incompatible with this list (optional).java.lang.NullPointerException - if the specified element is null and this
list does not support null elements (optional).public java.util.ListIterator<V> listIterator()
public java.util.ListIterator<V> listIterator(int index)
index - index of first element to be returned from the
list iterator (by a call to the
java.lang.IndexOutOfBoundsException - if the index is out of range (index
< 0 || index > size()).public java.util.List subList(int fromIndex,
int toIndex)
java.lang.UnsupportedOperationExceptionpublic boolean add(java.lang.Object o)
java.lang.UnsupportedOperationExceptionpublic boolean addAll(java.util.Collection c)
java.lang.UnsupportedOperationExceptionpublic boolean addAll(int index,
java.util.Collection c)
java.lang.UnsupportedOperationExceptionpublic void add(int index,
java.lang.Object element)
java.lang.UnsupportedOperationExceptionpublic V removeKey(K key)
key - key whose mapping is to be removed from the map.java.lang.ClassCastException - if the key is of an inappropriate type for
this map (optional).java.lang.NullPointerException - if the key is
public boolean removeValue(java.lang.Object o)
o - element to be removed from this list, if present.java.lang.ClassCastException - if the type of the specified element
is incompatible with this list (optional).java.lang.NullPointerException - if the specified element is null and this
list does not support null elements (optional).public void add(K key, V o)
key - The key.o - The object.public V replace(K key, V o)
key - The key.o - The object.public K getKey(int index)
index - The index.public void add(int index,
K key,
V o)
index - The index.key - The key.o - The object.public java.util.Map<K,V> getAsMap()
public java.util.List<V> getAsList()
public java.lang.Object[] getObjects()
public java.lang.Object[] getObjects(java.lang.Class type)
type - The component type of the array.public java.lang.Object[] getKeys()
public java.lang.Object[] getKeys(java.lang.Class<?> type)
type - The component type of the array.