Package jadex.commons.collection
Class MultiCollection<K,V>
- java.lang.Object
- 
- jadex.commons.collection.MultiCollection<K,V>
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- java.lang.Cloneable,- java.util.Map<K,java.util.Collection<V>>
 - Direct Known Subclasses:
- TwoWayMultiCollection
 
 public class MultiCollection<K,V> extends java.lang.Object implements java.util.Map<K,java.util.Collection<V>>, java.io.Serializable, java.lang.CloneableAn MultiCollection is a map with the ability to store more than one element per key (an collection).- See Also:
- Serialized Form
 
- 
- 
Constructor SummaryConstructors Constructor Description MultiCollection()Create a new multi collection.MultiCollection(java.util.Map<K,java.util.Collection<V>> map, java.lang.Class<?> type)Create a new multi collection.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Collection<V>add(K key, java.util.Collection<V> value)Associates the specified value with the specified key in this map (optional operation).java.util.Collection<V>add(K key, V value)Associates the specified value with the specified key in this map (optional operation).voidaddAll(java.util.Map<? extends K,? extends V> t)Add all elements of another map.voidclear()Removes all mappings from this map.java.lang.Objectclone()Clone a multi collection.booleancontainsKey(java.lang.Object key)ReturnsbooleancontainsValue(java.lang.Object value)Returnsjava.util.Collection<V>createCollection(K key)Create a collection instance.java.util.Set<java.util.Map.Entry<K,java.util.Collection<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.java.util.Collection<V>get(java.lang.Object key)Returns the collection to which this map maps the specified key.java.util.Collection<V>getCollection(java.lang.Object key)Get the values associated to a key as collection.java.lang.Object[]getKeys()Get the keys as array.java.lang.Object[]getKeys(java.lang.Class<?> type)Get the keys as array.VgetObject(java.lang.Object key)Get first object for a key (unwraps from collection).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.booleanisEmpty()Returnsjava.util.Set<K>keySet()Returns a set view of the keys contained in this map.java.util.Collection<V>put(K key, java.util.Collection<V> value)Associates the specified value with the specified key in this map (optional operation).voidputAll(java.util.Map<? extends K,? extends java.util.Collection<V>> t)Copies all of the mappings from the specified map to this map (optional operation).java.util.Collection<V>remove(java.lang.Object key)Removes the mapping for this key from this map if it is present.voidremoveObject(java.lang.Object key, java.lang.Object value)Remove a special object from the collection of a defined key.intsize()Returns the number of elements added to this map.java.lang.StringtoString()Create a string representation of this map.java.util.Collection<java.util.Collection<V>>values()Unsupported Operation.
 
- 
- 
- 
Method Detail- 
clonepublic java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionClone a multi collection.- Overrides:
- clonein class- java.lang.Object
- Throws:
- java.lang.CloneNotSupportedException
 
 - 
sizepublic int size() Returns the number of elements added to this map.
 - 
isEmptypublic boolean isEmpty() Returns- 
containsKeypublic boolean containsKey(java.lang.Object key) Returns- Specified by:
- containsKeyin interface- java.util.Map<K,V>
- 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- Specified by:
- containsValuein interface- java.util.Map<K,V>
- 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 java.util.Collection<V> get(java.lang.Object key) Returns the collection to which this map maps the specified key. Returns- Specified by:
- getin interface- java.util.Map<K,V>
- Parameters:
- key- key whose associated collection is to be returned.
- Returns:
- the collection 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)
 - 
getObjectpublic V getObject(java.lang.Object key) Get first object for a key (unwraps from collection).- Parameters:
- key- The key.
- Returns:
- The (first) value or null.
 
 - 
putpublic java.util.Collection<V> put(K key, java.util.Collection<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- Specified by:
- putin interface- java.util.Map<K,V>
- Parameters:
- key- key with which the specified value is to be associated.
- value- value to be associated with the specified key.
- Returns:
- The collection associated to the key.
- Throws:
- 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
 - 
addpublic java.util.Collection<V> add(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:
- The collection associated to the key.
- Throws:
- 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
 - 
addpublic java.util.Collection<V> add(K key, java.util.Collection<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:
- The collection associated to the key.
- Throws:
- 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
 - 
addAllpublic void addAll(java.util.Map<? extends K,? extends V> t) Add all elements of another map.- Parameters:
- t- The other map.
 
 - 
putAllpublic void putAll(java.util.Map<? extends K,? extends java.util.Collection<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- Specified by:
- putAllin interface- java.util.Map<K,V>
- 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. The set supports element removal, which removes the corresponding mapping from the map, via the- Specified by:
- keySetin interface- java.util.Map<K,V>
- Returns:
- a set view of the keys contained in this map.
 - 
valuespublic java.util.Collection<java.util.Collection<V>> values() Unsupported Operation.
 - 
entrySetpublic java.util.Set<java.util.Map.Entry<K,java.util.Collection<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. The set supports element removal, which removes the corresponding mapping from the map, via the- Specified by:
- entrySetin interface- java.util.Map<K,V>
- 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- Specified by:
- equalsin interface- java.util.Map<K,V>
- 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.- Specified by:
- hashCodein interface- java.util.Map<K,V>
- 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
 
 - 
removepublic java.util.Collection<V> remove(java.lang.Object 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.)- Specified by:
- removein interface- java.util.Map<K,V>
- Parameters:
- key- key whose mapping is to be removed from the map.
- Returns:
- collection 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
 - 
getCollectionpublic java.util.Collection<V> getCollection(java.lang.Object key) Get the values associated to a key as collection.- Parameters:
- key- The key.
- Returns:
- The collection of associated values.
 
 - 
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.
 
 - 
removeObjectpublic void removeObject(java.lang.Object key, java.lang.Object value)Remove a special object from the collection of a defined key.
 
 
 
 
 
 
 
 
 
 
 
 
- 
 
- 
 
-