Package com.pnfsoftware.jeb.util.collect
Class MultiMap<K,V>
java.lang.Object
com.pnfsoftware.jeb.util.collect.MultiMap<K,V>
- Type Parameters:
K
- key typeV
- type of value to be stored
A multi-map of key-values, whose insertion order for the values of a given key is maintained.
This class is
serialializable
. Null key is allowed; null values are allowed.
Thread-safety: none.
Note: this class does not implement the Map
interface, but attempts to follow its
guidelines and contracts the best it can. One notable exception is that this class does not
override hashCode/equals.
-
Constructor Summary
ConstructorsConstructorDescriptionMultiMap()
Create a new multi-map.MultiMap
(CollectionOrder keyOrder) Create a new multi-map. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
containsKey
(K key) boolean
containsValue
(V value) boolean
Create an explicit entry for a given key.Retrieve the list of values associated with the provided key.Retrieve the list of values associated with the provided key.Retrieve the list of values associated with the provided key.boolean
isEmpty()
keySet()
Retrieve a read-only view of the keys.int
keySize()
int
void
void
putMulti
(K key, Collection<? extends V> values) Add multiple elements mapped by the same key.boolean
removeAll
(Collection<K> keys) Remove all entries mapping to the collection of keys.int
removeMulti
(K key, Collection<? extends V> values) int
removeMulti
(K key, Collection<? extends V> values, boolean removeEmptyBucket) removeValue
(K key, V value) removeValue
(K key, V value, boolean removeEmptyBucket) int
size()
Get the number of key-value mappings (per Map interface).toString()
values()
-
Constructor Details
-
MultiMap
public MultiMap()Create a new multi-map. -
MultiMap
Create a new multi-map.- Parameters:
keyOrder
-
-
-
Method Details
-
clear
public void clear() -
keySize
public int keySize() -
isEmpty
public boolean isEmpty() -
size
public int size()Get the number of key-value mappings (per Map interface). That is, the number of values.- Returns:
-
put
-
putMulti
Add multiple elements mapped by the same key. Note that if an empty collection is provided, the entry for the provided key will not be be explicitly created.- Parameters:
key
-values
-
-
putAll
-
createKey
Create an explicit entry for a given key. If no values mapped by the given key previously existed, the associated value will be an empty collecction.- Parameters:
key
-- Returns:
- true if the map did not already contain the key; false otherwise (the key entry existed before)
-
containsKey
-
containsValue
-
get
Retrieve the list of values associated with the provided key.- Parameters:
key
- a keysafe
- if true, an empty list of values is returned if the key does not exist- Returns:
- a list, possibly null or empty (depending on the
safe
parameter}
-
get
Retrieve the list of values associated with the provided key. Same asget(key, safe=false)
.- Parameters:
key
- a key- Returns:
- a list, possibly null if nothing was
put
for the provided key
-
getSafe
Retrieve the list of values associated with the provided key. Same asget(key, safe=true)
.- Parameters:
key
-- Returns:
-
remove
-
removeValue
-
removeValue
-
removeMulti
-
removeMulti
-
values
-
keySet
Retrieve a read-only view of the keys.WARNING: This method does not respect the
Map.keySet()
contract: the set returned is read-only.- Returns:
- read-only view of the key set
-
removeAll
Remove all entries mapping to the collection of keys.Similar semantics as
Set.removeAll(Collection)
.- Parameters:
keys
-- Returns:
- true if the multi-map was modified
-
toString
-