Package com.yahoo.collections
Class ListMap<K,V>
java.lang.Object
com.yahoo.collections.ListMap<K,V>
A map holding multiple items at each key (using ArrayList and HashMap).
- Author:
- bratseth
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionentrySet()
Returns the entries of this.void
forEach
(BiConsumer<K, List<V>> action) void
freeze()
Irreversibly prevent changes to the content of this.Returns the List containing the elements with this key, or an empty list if there are no elements for this key.The same as getboolean
isFrozen()
Returns whether this allows changeskeySet()
Returns the keys of thisvoid
Put a key without adding a new value, such that there is an empty list of values if no values are already addedvoid
Puts an element into this.void
removeValue
(K key, int index) Removes the value at the given index.boolean
removeValue
(K key, V value) void
Put this map in the state where it has just the given value of the given keyint
size()
Returns the number of keys in this maptoString()
Collection<List<V>>
values()
Returns the list values of this
-
Constructor Details
-
ListMap
public ListMap() -
ListMap
Copy constructor. This will not be frozen even if the argument map is -
ListMap
-
-
Method Details
-
put
Puts an element into this. Multiple elements at the same position are added to the list at this key -
put
Put a key without adding a new value, such that there is an empty list of values if no values are already added -
replace
Put this map in the state where it has just the given value of the given key -
removeAll
-
removeValue
-
removeValue
Removes the value at the given index.- Returns:
- the removed value
- Throws:
IndexOutOfBoundsException
- if there is no value at the given index for this key
-
get
Returns the List containing the elements with this key, or an empty list if there are no elements for this key. The returned list can be modified to add and remove values if the value exists. -
getList
The same as get -
entrySet
Returns the entries of this. Entries will be unmodifiable if this is frozen. -
keySet
Returns the keys of this -
values
Returns the list values of this -
freeze
public void freeze()Irreversibly prevent changes to the content of this. If this is already frozen, this method does nothing. -
isFrozen
public boolean isFrozen()Returns whether this allows changes -
toString
-
size
public int size()Returns the number of keys in this map -
forEach
-