|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.pig.impl.util.MultiMap<K,V>
public class MultiMap<K,V>
An implementation of multi-map. We can't use Apache commons MultiValueMap because it isn't serializable. And we don't want to use MultiHashMap, as it is marked deprecated. This class can't extend Map, because it needs to change the semantics of put, so that you give it one key and one value, and it either creates a new entry with the key and a new collection of value (if the is not yet in the map) or adds the values to the existing collection for the key (if the key is already in the map).
Field Summary | |
---|---|
protected Map<K,ArrayList<V>> |
mMap
|
Constructor Summary | |
---|---|
MultiMap()
|
|
MultiMap(int size)
|
Method Summary | |
---|---|
void |
clear()
|
boolean |
containsKey(K key)
|
boolean |
containsValue(V val)
|
List<V> |
get(K key)
Get the collection of values associated with a given key. |
boolean |
isEmpty()
|
Set<K> |
keySet()
Get a set of all the keys in this map. |
void |
put(K key,
Collection<V> values)
Add a key to the map with a collection of elements. |
void |
put(K key,
V value)
Add an element to the map. |
V |
remove(K key,
V value)
Remove one value from an existing key. |
Collection<V> |
removeKey(K key)
Remove all the values associated with the given key |
int |
size()
Get the number of keys in the map. |
String |
toString()
|
Collection<V> |
values()
Get a single collection of all the values in the map. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Map<K,ArrayList<V>> mMap
Constructor Detail |
---|
public MultiMap()
public MultiMap(int size)
size
- Initial size of the mapMethod Detail |
---|
public void put(K key, V value)
key
- The key to store the value under. If the key already
exists the value will be added to the collection for that key, it
will not replace the existing value (as in a standard map).value
- value to store.public void put(K key, Collection<V> values)
key
- The key to store the value under. If the key already
exists the value will be added to the collection for that key, it
will not replace the existing value (as in a standard map).values
- collection of values to store.public List<V> get(K key)
key
- Key to fetch values for.
public V remove(K key, V value)
key
- Key to remove the value from.value
- Value to remove.
public Collection<V> removeKey(K key)
key
- the key to be removed
public Set<K> keySet()
public Collection<V> values()
public String toString()
toString
in class Object
public int size()
public boolean isEmpty()
public void clear()
public boolean containsKey(K key)
public boolean containsValue(V val)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |