Package com.yahoo.collections
Class ListMap<K,V>
- java.lang.Object
-
- com.yahoo.collections.ListMap<K,V>
-
public class ListMap<K,V> extends java.lang.Object
A map holding multiple items at each key (using ArrayList and HashMap).- Author:
- bratseth
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<java.util.Map.Entry<K,java.util.List<V>>>
entrySet()
Returns the entries of this.void
freeze()
Irreversibly prevent changes to the content of this.java.util.List<V>
get(K key)
Returns the List containing the elements with this key, or an empty list if there are no elements for this key.java.util.List<V>
getList(K key)
The same as getboolean
isFrozen()
Returns whether this allows changesjava.util.Set<K>
keySet()
Returns the keys of thisvoid
put(K key)
Put a key without adding a new value, such that there is an empty list of values if no values are already addedvoid
put(K key, V value)
Puts an element into this.void
removeAll(K key)
V
removeValue(K key, int index)
Removes the value at the given index.boolean
removeValue(K key, V value)
void
replace(K key, V value)
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 mapjava.lang.String
toString()
java.util.Collection<java.util.List<V>>
values()
Returns the list values of this
-
-
-
Method Detail
-
put
public void put(K key, V value)
Puts an element into this. Multiple elements at the same position are added to the list at this key
-
put
public void put(K key)
Put a key without adding a new value, such that there is an empty list of values if no values are already added
-
replace
public void replace(K key, V value)
Put this map in the state where it has just the given value of the given key
-
removeAll
public void removeAll(K key)
-
removeValue
public V removeValue(K key, int index)
Removes the value at the given index.- Returns:
- the removed value
- Throws:
java.lang.IndexOutOfBoundsException
- if there is no value at the given index for this key
-
get
public java.util.List<V> get(K key)
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.
-
entrySet
public java.util.Set<java.util.Map.Entry<K,java.util.List<V>>> entrySet()
Returns the entries of this. Entries will be unmodifiable if this is frozen.
-
keySet
public java.util.Set<K> keySet()
Returns the keys of this
-
values
public java.util.Collection<java.util.List<V>> 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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
size
public int size()
Returns the number of keys in this map
-
-