public class MultiCollection<K,V>
extends java.lang.Object
implements java.util.Map<K,java.util.Collection<V>>, java.io.Serializable, java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<K,java.util.Collection<V>> |
map
The map.
|
protected java.lang.Class<?> |
type
The collection type.
|
Constructor and 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.
|
Modifier and Type | Method and 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)
Returns true if this map contains a mapping for the specified
key.
|
boolean |
containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the
specified value.
|
java.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()
Returns true if this map contains no key-value mappings.
|
java.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.
|
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public int size()
public boolean isEmpty()
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<K,java.util.Collection<V>>
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 null and this map
does not not permit null keys (optional).public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<K,java.util.Collection<V>>
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 null and this map
does not not permit null values (optional).public java.util.Collection<V> get(java.lang.Object key)
get
in interface java.util.Map<K,java.util.Collection<V>>
key
- key whose associated collection is to be returned.java.lang.ClassCastException
- if the key is of an inappropriate type for
this map (optional).java.lang.NullPointerException
- key is null and this map does not
not permit null keys (optional).containsKey(Object)
public V getObject(java.lang.Object key)
key
- The key.public java.util.Collection<V> put(K key, java.util.Collection<V> value)
m.containsKey(k)
would return
true.))put
in interface java.util.Map<K,java.util.Collection<V>>
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 put operation is
not supported by this map.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 null
keys or values, and the specified key or value is
null.public java.util.Collection<V> add(K key, V value)
m.containsKey(k)
would return
true.))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 put operation is
not supported by this map.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 null
keys or values, and the specified key or value is
null.public java.util.Collection<V> add(K key, java.util.Collection<V> value)
m.containsKey(k)
would return
true.))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 put operation is
not supported by this map.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 null
keys or values, and the specified key or value is
null.public void addAll(java.util.Map<? extends K,? extends V> t)
t
- The other map.public void putAll(java.util.Map<? extends K,? extends java.util.Collection<V>> t)
put(k, v)
on this map once
for each mapping from key k to value v in the
specified map. The behavior of this operation is unspecified if the
specified map is modified while the operation is in progress.putAll
in interface java.util.Map<K,java.util.Collection<V>>
t
- Mappings to be stored in this map.java.lang.UnsupportedOperationException
- if the putAll method is
not supported by this map.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 null, or if
this map does not permit null keys or values, and the
specified map contains null keys or values.public void clear()
public java.util.Set<K> keySet()
public java.util.Collection<java.util.Collection<V>> values()
public java.util.Set<java.util.Map.Entry<K,java.util.Collection<V>>> entrySet()
public boolean equals(java.lang.Object o)
public int hashCode()
hashCode
in interface java.util.Map<K,java.util.Collection<V>>
hashCode
in class java.lang.Object
Object.hashCode()
,
Object.equals(Object)
,
equals(Object)
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.Collection<V> remove(java.lang.Object key)
(key==null ? k==null : key.equals(k))
, that mapping
is removed. (The map can contain at most one such mapping.)
Returns the value to which the map previously associated the key, or null if the map contained no mapping for this key. (A null return can also indicate that the map previously associated null with the specified key if the implementation supports null values.) The map will not contain a mapping for the specified key once the call returns.
remove
in interface java.util.Map<K,java.util.Collection<V>>
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 null and this map
does not not permit null keys (optional).public java.util.Collection<V> getCollection(java.lang.Object key)
key
- The key.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.public void removeObject(java.lang.Object key, java.lang.Object value)