Package com.attivio.util
Class MultiValueMap<K,V>
- java.lang.Object
-
- com.attivio.util.MultiValueMap<K,V>
-
- Type Parameters:
K- The key typeV- The value type
- All Implemented Interfaces:
java.io.Serializable,java.util.Map<K,java.util.Set<V>>
public class MultiValueMap<K,V> extends java.lang.Object implements java.util.Map<K,java.util.Set<V>>, java.io.SerializableMap implementation that can hold multiple unique values for a given key.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MultiValueMap()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<V>addValue(K key, V o)Adds a value for a given key.java.util.Set<V>addValues(K key, java.util.Collection<V> coll)Adds values for a given key.java.util.Set<V>addValues(K key, V... o)Adds values for a given key.voidclear()Removes all entries from the map.booleancontainsKey(java.lang.Object key)Determines if the map contains an entry for the given key.booleancontainsValue(java.lang.Object value)Determines if the map contains a value for any key.java.util.Set<java.util.Map.Entry<K,java.util.Set<V>>>entrySet()Gets the Set of Entries.java.util.Set<V>get(java.lang.Object key)Returns the first key.VgetFirstValue(java.lang.Object key)Gets the first/only value for a given key.intgetValueCount(java.lang.String key)Gets the number of values for a given key.java.util.Set<V>getValues(java.lang.Object key)Gets the full Set of values.booleanhasData()Determines if the map has any entries.booleanisEmpty()Determines if the map has any data.java.util.Set<K>keySet()Gets the set of keys.java.util.Set<V>put(K key, java.util.Set<V> value)voidputAll(java.util.Map<? extends K,? extends java.util.Set<V>> map)voidputOneFromEach(java.util.Map<K,V> t)Adds a single value for each entry in the map.java.util.Set<V>remove(java.lang.Object key)Removes all values for a key.java.lang.ObjectremoveValue(java.lang.String key, java.lang.Object value)Removes a specific value for a key.voidsetValues(K key, java.util.Collection<V> l)Sets the values for a given key replacing old ones if they existed.intsize()Gets the size of the map.java.lang.StringtoString()Gets a nice string-based representation of the map.java.util.Collection<java.util.Set<V>>values()Returns a Collection containing each set of values.java.util.Collection<V>valuesCollapsed()Returns a Collection containing all values from all keys.
-
-
-
Method Detail
-
getValues
public java.util.Set<V> getValues(java.lang.Object key)
Gets the full Set of values.- Parameters:
key- key to lookup values for- Returns:
- all values for the given key
-
getFirstValue
public V getFirstValue(java.lang.Object key)
Gets the first/only value for a given key.- Parameters:
key- key to lookup values for- Returns:
- the first/only value for a given key, null if not set
-
size
public int size()
Gets the size of the map.
-
setValues
public void setValues(K key, java.util.Collection<V> l)
Sets the values for a given key replacing old ones if they existed.- Parameters:
key- key to set values forl- the values for the key
-
addValue
public java.util.Set<V> addValue(K key, V o)
Adds a value for a given key.- Parameters:
key- key to add a value too- the objects to add- Returns:
- the set of objects
-
addValues
public java.util.Set<V> addValues(K key, java.util.Collection<V> coll)
Adds values for a given key.- Parameters:
key- key to add a value tocoll- the objects to add- Returns:
- the set of objects
-
addValues
public java.util.Set<V> addValues(K key, V... o)
Adds values for a given key.- Parameters:
key- key to add a value too- the object to add- Returns:
- the set of objects
-
keySet
public java.util.Set<K> keySet()
Gets the set of keys.
-
hasData
public boolean hasData()
Determines if the map has any entries.- Returns:
- true if size()>0
-
toString
public java.lang.String toString()
Gets a nice string-based representation of the map.- Overrides:
toStringin classjava.lang.Object- Returns:
- string-based representation of the map
-
clear
public void clear()
Removes all entries from the map.
-
containsKey
public boolean containsKey(java.lang.Object key)
Determines if the map contains an entry for the given key.
-
containsValue
public boolean containsValue(java.lang.Object value)
Determines if the map contains a value for any key. If value is a Set checks to see if a set matches, otherwise checks for an individual value. Note: uses equals() to check for equality.
-
entrySet
public java.util.Set<java.util.Map.Entry<K,java.util.Set<V>>> entrySet()
Gets the Set of Entries.
-
get
public java.util.Set<V> get(java.lang.Object key)
Returns the first key.- Specified by:
getin interfacejava.util.Map<K,V>- Parameters:
key- the key to lookup- Returns:
- the first value for the key
- See Also:
getFirstValue(Object)
-
isEmpty
public boolean isEmpty()
Determines if the map has any data.
-
putOneFromEach
public void putOneFromEach(java.util.Map<K,V> t)
Adds a single value for each entry in the map.- Parameters:
t- the map to add
-
remove
public java.util.Set<V> remove(java.lang.Object key)
Removes all values for a key.
-
removeValue
public java.lang.Object removeValue(java.lang.String key, java.lang.Object value)Removes a specific value for a key.- Parameters:
key- the key to lookupvalue- the value to remove- Returns:
- the removed value
-
values
public java.util.Collection<java.util.Set<V>> values()
Returns a Collection containing each set of values. see alsovaluesCollapsed().
-
valuesCollapsed
public java.util.Collection<V> valuesCollapsed()
Returns a Collection containing all values from all keys.- Returns:
- the list of all values for all keys
-
getValueCount
public int getValueCount(java.lang.String key)
Gets the number of values for a given key.- Parameters:
key- the key to lookup- Returns:
- the number of items
-
-