Package jadex.commons.collection
Class IndexMap<K,V>
- java.lang.Object
- 
- jadex.commons.collection.IndexMap<K,V>
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- java.lang.Cloneable
 - Direct Known Subclasses:
- IndexMap.ListIndexMap,- IndexMap.MapIndexMap
 
 public class IndexMap<K,V> extends java.lang.Object implements java.io.Serializable, java.lang.CloneableThis class combines the list and map interface. So it provides fast lookup (via map) and ordering (via list). Because the remove(Object) method has different return types in map and list, index map cannot implement both interfaces. Methods are provided to get a map instance and a list instance of an index map.- See Also:
- Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classIndexMap.ListIndexMap<K,V>Provide access to the index map via list interface.static classIndexMap.MapIndexMap<K,V>Provide access to the index map via map interface.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, java.lang.Object element)Unsupported method, due to missing key parameter.voidadd(int index, K key, V o)Add an object to the collection.booleanadd(java.lang.Object o)Unsupported method, due to missing key parameter.voidadd(K key, V o)Add a new object with key and value.booleanaddAll(int index, java.util.Collection c)Unsupported method, due to missing key parameter.booleanaddAll(java.util.Collection c)Unsupported method, due to missing key parameter.voidclear()Removes all mappings from this map.java.lang.Objectclone()Clone an index map.booleancontains(java.lang.Object o)ReturnsbooleancontainsAll(java.util.Collection<?> c)ReturnsbooleancontainsKey(java.lang.Object key)ReturnsbooleancontainsValue(java.lang.Object value)Returnsjava.util.Set<java.util.Map.Entry<K,V>>entrySet()Returns a set view of the mappings contained in this map.booleanequals(java.lang.Object o)Compares the specified object with this map for equality.Vget(int index)Returns the element at the specified position in this list.Vget(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.KgetKey(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.inthashCode()Returns the hash code value for this map.intindexOf(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.booleanisEmpty()Returnsjava.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.intlastIndexOf(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.Vput(K key, V value)Associates the specified value with the specified key in this map (optional operation).voidputAll(java.util.Map<? extends K,? extends V> t)Copies all of the mappings from the specified map to this map (optional operation).Vremove(int index)Removes the element at the specified position in this list.booleanremoveAll(java.util.Collection<?> c)Removes from this list all the elements that are contained in the specified collection.VremoveKey(K key)Removes the mapping for this key from this map if it is present.booleanremoveValue(java.lang.Object o)Removes the first occurrence in this list of the specified element.Vreplace(K key, V o)Replace an object for the given key.booleanretainAll(java.util.Collection<?> c)Retains only the elements in this list that are contained in the specified collection.Vset(int index, V element)Replaces the element at the specified position in this list with the specified element.intsize()Returns the number of key-value mappings in this map.java.util.ListsubList(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.StringtoString()Create a string representation of this map.java.util.Collection<V>values()Returns a collection view of the values contained in this map.
 
- 
- 
- 
Method Detail- 
clonepublic java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionClone an index map.- Overrides:
- clonein class- java.lang.Object
- Throws:
- java.lang.CloneNotSupportedException
 
 - 
sizepublic int size() Returns the number of key-value mappings in this map. If the map contains more than- Returns:
- the number of key-value mappings in this map.
 - 
isEmptypublic boolean isEmpty() Returns- Returns:
 - 
containsKeypublic boolean containsKey(java.lang.Object key) Returns- Parameters:
- key- key whose presence in this map is to be tested.
- Returns:
- 
- Throws:
java.lang.ClassCastException- if the key is of an inappropriate type for this map (optional).java.lang.NullPointerException- if the key is
 - 
containsValuepublic boolean containsValue(java.lang.Object value) Returns- Parameters:
- value- value whose presence in this map is to be tested.
- Returns:
- 
- Throws:
java.lang.ClassCastException- if the value is of an inappropriate type for this map (optional).java.lang.NullPointerException- if the value is
 - 
getpublic V get(java.lang.Object key) Returns the value to which this map maps the specified key. Returns- Parameters:
- key- key whose associated value is to be returned.
- Returns:
- the value to which this map maps the specified key, or
               
- Throws:
java.lang.ClassCastException- if the key is of an inappropriate type for this map (optional).java.lang.NullPointerException- key is
- See Also:
containsKey(Object)
 - 
putpublic V put(K key, V value) Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for this key, the old value is replaced by the specified value. (A mapm.containsKey(k)would return- Parameters:
- key- key with which the specified value is to be associated.
- value- value to be associated with the specified key.
- Returns:
- previous value associated with specified key, or 
- Throws:
java.lang.UnsupportedOperationException- if thejava.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
 - 
putAllpublic void putAll(java.util.Map<? extends K,? extends V> t) Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of callingput(k, v)on this map once for each mapping from key- Parameters:
- t- Mappings to be stored in this map.
- Throws:
- 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
 - 
clearpublic void clear() Removes all mappings from this map.
 - 
keySetpublic java.util.Set<K> keySet() Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. No key order is reflected in the set!- Returns:
- a set view of the keys contained in this map.
 
 - 
valuespublic java.util.Collection<V> values() Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress, the results of the iteration are undefined.- Returns:
- a collection view of the values contained in this map.
 
 - 
entrySetpublic java.util.Set<java.util.Map.Entry<K,V>> entrySet() Returns a set view of the mappings contained in this map. Each element in the returned set is a Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. No key order is reflected in the set!- Returns:
- a set view of the mappings contained in this map.
 
 - 
equalspublic boolean equals(java.lang.Object o) Compares the specified object with this map for equality. Returns- Overrides:
- equalsin class- java.lang.Object
- Parameters:
- o- object to be compared for equality with this map.
- Returns:
 - 
hashCodepublic int hashCode() Returns the hash code value for this map.- Overrides:
- hashCodein class- java.lang.Object
- Returns:
- the hash code value for this map.
- See Also:
- Object.hashCode(),- Object.equals(Object),- equals(Object)
 
 - 
toStringpublic java.lang.String toString() Create a string representation of this map.- Overrides:
- toStringin class- java.lang.Object
 
 - 
containspublic boolean contains(java.lang.Object o) Returns- Parameters:
- o- element whose presence in this list is to be tested.
- Returns:
- 
- Throws:
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).
 - 
iteratorpublic java.util.Iterator<V> iterator() Returns an iterator over the elements in this list in proper sequence.- Returns:
- an iterator over the elements in this list in proper sequence.
 
 - 
toArraypublic java.lang.Object[] toArray() Returns an array containing all of the elements in this list in proper sequence. Obeys the general contract of the- Returns:
- an array containing all of the elements in this list in proper sequence.
- See Also:
- Arrays.asList(Object[])
 - 
toArraypublic <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. Obeys the general contract of the- Parameters:
- 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.
- Returns:
- an array containing the elements of this list.
- Throws:
- 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
 - 
containsAllpublic boolean containsAll(java.util.Collection<?> c) Returns- Parameters:
- c- collection to be checked for containment in this list.
- Returns:
- 
- Throws:
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
- See Also:
contains(Object)
 - 
removeAllpublic boolean removeAll(java.util.Collection<?> c) Removes from this list all the elements that are contained in the specified collection.- Parameters:
- c- collection that defines which elements will be removed from this list.
- Returns:
- 
- Throws:
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
- See Also:
removeValue(Object),contains(Object)
 
 - 
retainAllpublic boolean retainAll(java.util.Collection<?> c) Retains only the elements in this list that are contained in the specified collection. In other words, removes from this list all the elements that are not contained in the specified collection.- Parameters:
- c- collection that defines which elements this set will retain.
- Returns:
- 
- Throws:
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
- See Also:
removeValue(Object),contains(Object)
 
 - 
getpublic V get(int index) Returns the element at the specified position in this list.- Parameters:
- index- index of element to return.
- Returns:
- the element at the specified position in this list.
- Throws:
- java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size()).
 
 - 
setpublic V set(int index, V element) Replaces the element at the specified position in this list with the specified element.- Parameters:
- index- index of element to replace.
- element- element to be stored at the specified position.
- Returns:
- the element previously at the specified position.
- Throws:
- 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()).
 
 - 
removepublic V remove(int index) Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.- Parameters:
- index- the index of the element to removed.
- Returns:
- the element previously at the specified position.
- Throws:
- java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size()).
 
 - 
indexOfpublic 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. More formally, returns the lowest index- Parameters:
- o- element to search for.
- Returns:
- the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
- Throws:
- 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).
 - 
lastIndexOfpublic 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. More formally, returns the highest index- Parameters:
- o- element to search for.
- Returns:
- the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.
- Throws:
- 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).
 - 
listIteratorpublic java.util.ListIterator<V> listIterator() Returns a list iterator of the elements in this list (in proper sequence).- Returns:
- a list iterator of the elements in this list (in proper sequence).
 
 - 
listIteratorpublic 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. The specified index indicates the first element that would be returned by an initial call to the- Parameters:
- index- index of first element to be returned from the list iterator (by a call to the
- Returns:
- a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.
- Throws:
- java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index > size()).
 - 
subListpublic java.util.List subList(int fromIndex, int toIndex)Unsupported method.- Throws:
- java.lang.UnsupportedOperationException
 
 - 
addpublic boolean add(java.lang.Object o) Unsupported method, due to missing key parameter.- Throws:
- java.lang.UnsupportedOperationException
 
 - 
addAllpublic boolean addAll(java.util.Collection c) Unsupported method, due to missing key parameter.- Throws:
- java.lang.UnsupportedOperationException
 
 - 
addAllpublic boolean addAll(int index, java.util.Collection c)Unsupported method, due to missing key parameter.- Throws:
- java.lang.UnsupportedOperationException
 
 - 
addpublic void add(int index, java.lang.Object element)Unsupported method, due to missing key parameter.- Throws:
- java.lang.UnsupportedOperationException
 
 - 
removeKeypublic V removeKey(K key) Removes the mapping for this key from this map if it is present. More formally, if this map contains a mapping from key (key==null ? k==null : key.equals(k)), that mapping is removed. (The map can contain at most one such mapping.)- Parameters:
- key- key whose mapping is to be removed from the map.
- Returns:
- previous value associated with specified key, or 
- Throws:
java.lang.ClassCastException- if the key is of an inappropriate type for this map (optional).java.lang.NullPointerException- if the key is
 - 
removeValuepublic boolean removeValue(java.lang.Object o) Removes the first occurrence in this list of the specified element. If this list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that- Parameters:
- o- element to be removed from this list, if present.
- Returns:
- 
- Throws:
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).
 - 
addpublic void add(K key, V o) Add a new object with key and value. The key must not exist.- Parameters:
- key- The key.
- o- The object.
 
 - 
replacepublic V replace(K key, V o) Replace an object for the given key. The key has to exist.- Parameters:
- key- The key.
- o- The object.
- Returns:
- The old value for the key.
 
 - 
getKeypublic K getKey(int index) Get an indexed key.- Parameters:
- index- The index.
- Returns:
- The key.
 
 - 
addpublic void add(int index, K key, V o)Add an object to the collection.- Parameters:
- index- The index.
- key- The key.
- o- The object.
 
 - 
getAsMappublic java.util.Map<K,V> getAsMap() Return an instance of this index map accessible via map interface.
 - 
getAsListpublic java.util.List<V> getAsList() Return an instance of this index map accessible via list interface.
 - 
getObjectspublic java.lang.Object[] getObjects() Get the values as array.- Returns:
- The array of values.
 
 - 
getObjectspublic java.lang.Object[] getObjects(java.lang.Class type) Get the values as array.- Parameters:
- type- The component type of the array.
- Returns:
- The array of values.
 
 - 
getKeyspublic java.lang.Object[] getKeys() Get the keys as array.- Returns:
- The array of keys.
 
 - 
getKeyspublic java.lang.Object[] getKeys(java.lang.Class<?> type) Get the keys as array.- Parameters:
- type- The component type of the array.
- Returns:
- The array of keys.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
- 
 
-