|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectch.javasoft.util.map.AbstractMultiValueMap<K,V>
ch.javasoft.util.map.AbstractMutableMultiValueMap<K,V>
ch.javasoft.util.map.DefaultMultiValueMap<K,V>
public class DefaultMultiValueMap<K,V>
Default implementation for a mutable MultiValueMap.
The standard implementation is backed by a LinkedHashMap containing
an ArrayList per key. The backing map and collection can be changed
by overriding createMap() and createCollection(Object),
respectively.
| Constructor Summary | |
|---|---|
DefaultMultiValueMap()
Constructor for an empty multi value map |
|
DefaultMultiValueMap(Map<K,Collection<V>> collectionMap)
Constructor for a multi value map based on the given collection map. |
|
DefaultMultiValueMap(MultiValueMap<? extends K,? extends V> copy)
Constructor for a multi value map based on an existing one |
|
| Method Summary | ||
|---|---|---|
boolean |
add(K key,
V value)
Adds the given value to the multi value map |
|
boolean |
addAll(K key,
Collection<? extends V> values)
Adds the given values to the key collection |
|
boolean |
clear()
Removes all entries from this mapping |
|
DefaultMultiValueMap<K,V> |
clone()
|
|
boolean |
contains(Object key)
Returns true if the value collection is non-empty |
|
boolean |
contains(Object key,
V value)
Returns true if the value collection contains at least one occurrence of the given value |
|
int |
count(Object key)
Returns the number of values in the value collection |
|
protected Collection<V> |
createCollection(K key)
Returns a new collection instance. |
|
static
|
createFromCollectionMap(Map<? extends K,? extends Collection<? extends V>> collectionMap)
Creates a multi value map from an existing collection map. |
|
static
|
createFromSingleValueMap(Map<? extends K,? extends V> singleMap)
Creates a multi value map from an existing (single value) map |
|
protected Map<K,Collection<V>> |
createMap()
Returns a new map instance. |
|
Collection<V> |
get(Object key)
Returns an unmodifiable value collection. |
|
V |
getFirst(Object key)
Returns the first value of the value collection, or null if no such value exists |
|
protected Collection<V> |
getOrCreateCollection(K key)
Returns the value collection for the specified key. |
|
boolean |
isEmpty()
Returns true if this map is empty |
|
Set<K> |
keySet()
Returns an modifiable key set, i.e. |
|
boolean |
remove(Object key)
Returns all values belonging to this key, i.e. |
|
boolean |
remove(Object key,
V value)
Returns a single value of the value collection, if it exists |
|
Iterable<V> |
values()
Returns an unmodifiable iterator for all values |
|
| Methods inherited from class ch.javasoft.util.map.AbstractMutableMultiValueMap |
|---|
addAll, addAll, addAll, addAllNested |
| Methods inherited from class ch.javasoft.util.map.AbstractMultiValueMap |
|---|
asCollectionMap, asSingleValueMap, equals, hashCode, invert, keySize, toString, valueSize |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DefaultMultiValueMap()
public DefaultMultiValueMap(MultiValueMap<? extends K,? extends V> copy)
public DefaultMultiValueMap(Map<K,Collection<V>> collectionMap)
createFromCollectionMap(Map) can be used.
collectionMap - the map to use for this multi value map| Method Detail |
|---|
public static <K,V> DefaultMultiValueMap<K,V> createFromSingleValueMap(Map<? extends K,? extends V> singleMap)
K - the key typeV - the value typesingleMap - the map containing key/value pairs to add to the new map
public static <K,V> DefaultMultiValueMap<K,V> createFromCollectionMap(Map<? extends K,? extends Collection<? extends V>> collectionMap)
K - the key typeV - the value typecollectionMap - the map containing key/list-of-value entries to add
to the new map
public boolean add(K key,
V value)
add in interface MultiValueMap<K,V>add in class AbstractMultiValueMap<K,V>key - the key which identifies the value collectionvalue - the value to add
UnsupportedOperationException - if this is an immutable map
public boolean addAll(K key,
Collection<? extends V> values)
AbstractMutableMultiValueMap
addAll in interface MultiValueMap<K,V>addAll in class AbstractMutableMultiValueMap<K,V>key - the key which identifies the value collectionvalues - the values to add
public Collection<V> get(Object key)
get in interface MultiValueMap<K,V>key - the key which identifies the value collection
MultiValueMap.get(Object)public V getFirst(Object key)
MultiValueMap
getFirst in interface MultiValueMap<K,V>getFirst in class AbstractMultiValueMap<K,V>key - the key which identifies the value collection
public int count(Object key)
MultiValueMap
count in interface MultiValueMap<K,V>key - the key which identifies the value collection
public boolean isEmpty()
MultiValueMap
isEmpty in interface MultiValueMap<K,V>isEmpty in class AbstractMultiValueMap<K,V>public boolean contains(Object key)
MultiValueMap
contains in interface MultiValueMap<K,V>contains in class AbstractMultiValueMap<K,V>key - the key which identifies the value collection
public boolean contains(Object key,
V value)
MultiValueMap
contains in interface MultiValueMap<K,V>key - the key which identifies the value collectionvalue - the value to look for
public boolean remove(Object key)
remove in interface MultiValueMap<K,V>remove in class AbstractMultiValueMap<K,V>key - the key which identifies the value collection
UnsupportedOperationException - if this is an immutable map
public boolean remove(Object key,
V value)
remove in interface MultiValueMap<K,V>remove in class AbstractMultiValueMap<K,V>key - the key which identifies the value collectionvalue - the value to remove
UnsupportedOperationException - if this is an immutable mappublic boolean clear()
clear in interface MultiValueMap<K,V>clear in class AbstractMultiValueMap<K,V>UnsupportedOperationException - if this is an immutable mappublic Set<K> keySet()
keySet in interface MultiValueMap<K,V>MultiValueMap.get(Object)public Iterable<V> values()
values in interface MultiValueMap<K,V>values in class AbstractMultiValueMap<K,V>MultiValueMap.values()public DefaultMultiValueMap<K,V> clone()
clone in class Objectprotected Collection<V> getOrCreateCollection(K key)
created and added to the backing
map.
key - the key identifying the value collection
protected Collection<V> createCollection(K key)
ArrayList of
size one is created. The method shall never return null.
key - the key for which a value collection is to be created
protected Map<K,Collection<V>> createMap()
LinkedHashMap is
created. The method shall never return null.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||