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.Cloneable
An MultiCollection is a map with the ability to store more than one element per key (an collection).- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors 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 Summary
All 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).void
addAll(java.util.Map<? extends K,? extends V> t)
Add all elements of another map.void
clear()
Removes all mappings from this map.java.lang.Object
clone()
Clone a multi collection.boolean
containsKey(java.lang.Object key)
Returnsboolean
containsValue(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.boolean
equals(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.V
getObject(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.int
hashCode()
Returns the hash code value for this map.boolean
isEmpty()
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).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).java.util.Collection<V>
remove(java.lang.Object key)
Removes the mapping for this key from this map if it is present.void
removeObject(java.lang.Object key, java.lang.Object value)
Remove a special object from the collection of a defined key.int
size()
Returns the number of elements added to this map.java.lang.String
toString()
Create a string representation of this map.java.util.Collection<java.util.Collection<V>>
values()
Unsupported Operation.
-
-
-
Method Detail
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Clone a multi collection.- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
size
public int size()
Returns the number of elements added to this map.
-
isEmpty
public boolean isEmpty()
Returns-
containsKey
public boolean containsKey(java.lang.Object key)
Returns- Specified by:
containsKey
in interfacejava.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
-
containsValue
public boolean containsValue(java.lang.Object value)
Returns- Specified by:
containsValue
in interfacejava.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
-
get
public java.util.Collection<V> get(java.lang.Object key)
Returns the collection to which this map maps the specified key. Returns- Specified by:
get
in interfacejava.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)
-
getObject
public 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.
-
put
public 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:
put
in interfacejava.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 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
-
add
public 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 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
-
add
public 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 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
-
addAll
public void addAll(java.util.Map<? extends K,? extends V> t)
Add all elements of another map.- Parameters:
t
- The other map.
-
putAll
public 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:
putAll
in interfacejava.util.Map<K,V>
- Parameters:
t
- Mappings to be stored in this map.- Throws:
java.lang.UnsupportedOperationException
- if thejava.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
-
clear
public void clear()
Removes all mappings from this map.
-
keySet
public 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:
keySet
in interfacejava.util.Map<K,V>
- Returns:
- a set view of the keys contained in this map.
-
values
public java.util.Collection<java.util.Collection<V>> values()
Unsupported Operation.
-
entrySet
public 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:
entrySet
in interfacejava.util.Map<K,V>
- Returns:
- a set view of the mappings contained in this map.
-
equals
public boolean equals(java.lang.Object o)
Compares the specified object with this map for equality. Returns- Specified by:
equals
in interfacejava.util.Map<K,V>
- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- object to be compared for equality with this map.- Returns:
-
hashCode
public int hashCode()
Returns the hash code value for this map.- Specified by:
hashCode
in interfacejava.util.Map<K,V>
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hash code value for this map.
- See Also:
Object.hashCode()
,Object.equals(Object)
,equals(Object)
-
toString
public java.lang.String toString()
Create a string representation of this map.- Overrides:
toString
in classjava.lang.Object
-
remove
public 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:
remove
in interfacejava.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
-
getCollection
public 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.
-
getObjects
public java.lang.Object[] getObjects()
Get the values as array.- Returns:
- The array of values.
-
getObjects
public 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.
-
getKeys
public java.lang.Object[] getKeys()
Get the keys as array.- Returns:
- The array of keys.
-
getKeys
public 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.
-
removeObject
public void removeObject(java.lang.Object key, java.lang.Object value)
Remove a special object from the collection of a defined key.
-
-
-