K
- The key of the multi-mapV
- The types in the multi-mappublic class MultiMap<K,V>
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
NEWLINE |
private static long |
serialVersionUID
For serialization
|
private java.util.Map<K,java.util.List<V>> |
store |
Constructor and Description |
---|
MultiMap()
Creates an empty multi-map with default concurrency controls
|
MultiMap(MultiMap<K,V> base)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
private java.util.List<V> |
_get(K k)
Package private (for getting the raw map for direct manipulation by the habitat)
|
void |
add(K k,
V v)
Adds one more key-value pair.
|
MultiMap<K,V> |
clone()
Creates a copy of the map that contains the exact same key and value set.
|
boolean |
contains(K k1,
V k2)
Checks if the map contains the given key(s), also extending the search
to including the sub collection.
|
boolean |
containsKey(K k)
Checks if the map contains the given key.
|
java.util.Set<java.util.Map.Entry<K,java.util.List<V>>> |
entrySet()
Lists up all entries.
|
boolean |
equals(java.lang.Object another) |
java.util.List<V> |
get(K k)
Returns the elements indexed by the provided key
|
private V |
getFirst(K k) |
V |
getOne(K k)
Gets the first value if any, or null.
|
int |
hashCode() |
java.util.Set<K> |
keySet()
Returns the set of keys associated with this MultiMap
|
void |
mergeAll(MultiMap<K,V> another)
This method merges all of the keys and values from another
MultiMap into this MultiMap.
|
private java.util.List<V> |
newList(java.util.Collection<? extends V> initialVals)
Creates an optionally populated list to be used as an entry in the map.
|
java.util.List<V> |
remove(K key)
Removes an key value from the map
|
boolean |
remove(K key,
V entry)
Removes an key value pair from the map.
|
void |
set(K k,
java.util.Collection<? extends V> v)
Replaces all the existing values associated with the key
by the given value.
|
void |
set(K k,
V v)
Replaces all the existing values associated with the key
by the given single value.
|
int |
size()
Returns the size of the map.
|
java.lang.String |
toCommaSeparatedString() |
java.lang.String |
toString() |
private static final long serialVersionUID
private static final java.lang.String NEWLINE
public MultiMap()
private java.util.List<V> newList(java.util.Collection<? extends V> initialVals)
initialVal
- public java.util.Set<K> keySet()
public final void add(K k, V v)
k
- key to store the entry underv
- value to store in the k's values.public void set(K k, java.util.Collection<? extends V> v)
k
- key for the valuesv
- Can be null or empty.public void set(K k, V v)
k
- key for the valuesv
- singleton value for k key
This is short for set(k,Collections.singleton(v))public final java.util.List<V> get(K k)
k
- key for the valuespublic void mergeAll(MultiMap<K,V> another)
another
- The MultiMap from which to add values
to this MultiMap. If null this method does nothingprivate final java.util.List<V> _get(K k)
k
- the keypublic boolean containsKey(K k)
k
- key to testpublic boolean contains(K k1, V k2)
k1
- key from top collectionk2
- key (value) from inner collectionpublic java.util.List<V> remove(K key)
key
- key to be removedpublic boolean remove(K key, V entry)
key
- key to be removedentry
- the entry to be removed from the key'ed listpublic V getOne(K k)
k
- key for the valuespublic java.util.Set<java.util.Map.Entry<K,java.util.List<V>>> entrySet()
Set
of Map.Entry
of entriespublic java.lang.String toCommaSeparatedString()
public MultiMap<K,V> clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public int size()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object another)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object