Package org.faktorips.util
Class MultiMap<K,V>
java.lang.Object
org.faktorips.util.MultiMap<K,V>
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
SortedMultiMap
A data structure that maps a key to a collection of values. Adding a value to the map is like
putting a value to the collection regarding the specified key. If a value is requested by using
the key a collection is returned.
Different kinds of multi maps can be created using different
collection factories, or by calling the creator methods
createWithListsAsValues() and createWithSetsAsValues(). The map then contains
only lists or only sets respectively, depending on the use case.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interfaceFactory for creating collection instances to be used as values in aMultiMap.static classstatic class -
Constructor Summary
ConstructorsModifierConstructorDescriptionMultiMap()protectedMultiMap(Map<K, Collection<V>> map, MultiMap.CollectionFactory<V> collectionFactory) MultiMap(MultiMap.CollectionFactory<V> collectionFactory) Creates a newMultiMapwith an givenMultiMap.CollectionFactory. -
Method Summary
Modifier and TypeMethodDescriptionMap<K, Collection<V>> asMap()Returns an unmodifiableMapcontaining the entries of this multi map.voidclear()Removes all mappings from this map.intcount()Returns the count of objects contained in this multi map.static <K,V> MultiMap <K, V> static <K,V> MultiMap <K, V> static <K,V> MultiMap <K, V> This method returns collection to which the specified key is mapped.booleanisEmpty()Returns true if this multi map contains no key-value pairs.keySet()Returns the key-set of the internal map.voidMerges the specified multi map to this multi map.voidput(K key, Collection<V> values) Adds the specified values to the collection the key maps to.final voidAdds the specified values to the collection the key maps to.voidputReplace(K key, Collection<V> values) Put the collection of values into the map, identified by the specified key.Removes key and its associated collection from the map.voidRemoves the value in the collection the key maps to.values()
-
Constructor Details
-
MultiMap
-
MultiMap
public MultiMap() -
MultiMap
Creates a newMultiMapwith an givenMultiMap.CollectionFactory.- Parameters:
collectionFactory- the collection factory to use
-
-
Method Details
-
createWithSetsAsValues
-
createWithListsAsValues
-
createWithLinkedSetAsValues
-
put
Adds the specified values to the collection the key maps to.- Parameters:
key- key indicating the target Collection of the specified value that is to be associatedvalues- to be integrated in the Collection of the associated key
-
put
Adds the specified values to the collection the key maps to.- Parameters:
key- key indicating the target Collection of the specified value that is to be associatedvalues- to be integrated in the Collection of the associated key
-
merge
Merges the specified multi map to this multi map. That means: for every entry in the other multi map callput(Object, Collection).- Parameters:
otherMultiMap- The map that should be merged into this multi map
-
putReplace
Put the collection of values into the map, identified by the specified key. If the key already maps another collection, the old collection is replaced.- Parameters:
key- key indicating the specified values in the mapvalues- The collection of values that should be associated with the key
-
remove
Removes the value in the collection the key maps to.- Parameters:
key- to which the Collection is mappedvalue- to be removed from the collection the key maps to
-
remove
Removes key and its associated collection from the map.- Parameters:
key- to which the Collection is mapped- Returns:
- The collection that was stored in the list. Returns an empty collection if there was no such key.
-
get
This method returns collection to which the specified key is mapped. If the key does not exist an empty List is returned.- Parameters:
key- The key containing the wanted associated Collection- Returns:
- the collection to which the specified key is mapped
-
keySet
Returns the key-set of the internal map. Changes to this set (especially removing values) are reflected in thisMultiMapaccording toMap.keySet(). -
values
-
count
public int count()Returns the count of objects contained in this multi map. That means the sum of the size of all value collections.- Returns:
- The count of objects in this multi map;
-
clear
public void clear()Removes all mappings from this map. -
asMap
Returns an unmodifiableMapcontaining the entries of this multi map.- Returns:
- an unmodifiable view of this Map.
-
isEmpty
public boolean isEmpty()Returns true if this multi map contains no key-value pairs.- Returns:
trueif empty
-