public class

MultiMap

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.collect.MultiMap<K, V>

Class Overview

A multi-map of key-values, whose insertion order for the values of a given key is maintained. This class is serialializable. Null key is allowed; null values are allowed.

Thread-safety: none.

Note: this class does not implement the Map interface, but attempts to follow its guidelines and contracts the best it can. One notable exception is that this class does not override hashCode/equals.

Summary

Public Constructors
MultiMap()
Create a new multi-map.
MultiMap(CollectionOrder keyOrder)
Create a new multi-map.
Public Methods
void clear()
boolean containsKey(K key)
boolean containsValue(V value)
boolean createKey(K key)
Create an explicit entry for a given key.
List<V> get(K key, boolean safe)
Retrieve the list of values associated with the provided key.
List<V> get(K key)
Retrieve the list of values associated with the provided key.
List<V> getSafe(K key)
Retrieve the list of values associated with the provided key.
boolean isEmpty()
Set<K> keySet()
Retrieve a read-only view of the keys.
int keySize()
int put(K key, V value)
void putAll(Map<? extends K, List<? extends V>> m)
void putMulti(K key, Collection<? extends V> values)
Add multiple elements mapped by the same key.
List<V> remove(K key)
boolean removeAll(Collection<K> keys)
Remove all entries mapping to the collection of keys.
int removeMulti(K key, Collection<? extends V> values, boolean removeEmptyBucket)
int removeMulti(K key, Collection<? extends V> values)
V removeValue(K key, V value, boolean removeEmptyBucket)
V removeValue(K key, V value)
int size()
Get the number of key-value mappings (per Map interface).
String toString()
Collection<V> values()
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public MultiMap ()

Create a new multi-map.

public MultiMap (CollectionOrder keyOrder)

Create a new multi-map.

Public Methods

public void clear ()

public boolean containsKey (K key)

public boolean containsValue (V value)

public boolean createKey (K key)

Create an explicit entry for a given key. If no values mapped by the given key previously existed, the associated value will be an empty collecction.

Returns
  • true if the map did not already contain the key; false otherwise (the key entry existed before)

public List<V> get (K key, boolean safe)

Retrieve the list of values associated with the provided key.

Parameters
key a key
safe if true, an empty list of values is returned if the key does not exist
Returns
  • a list, possibly null or empty (depending on the safe parameter}

public List<V> get (K key)

Retrieve the list of values associated with the provided key. Same as get(key, safe=false).

Parameters
key a key
Returns
  • a list, possibly null if nothing was put for the provided key

public List<V> getSafe (K key)

Retrieve the list of values associated with the provided key. Same as get(key, safe=true).

public boolean isEmpty ()

public Set<K> keySet ()

Retrieve a read-only view of the keys.

WARNING: This method does not respect the keySet() contract: the set returned is read-only.

Returns
  • read-only view of the key set

public int keySize ()

public int put (K key, V value)

public void putAll (Map<? extends K, List<? extends V>> m)

public void putMulti (K key, Collection<? extends V> values)

Add multiple elements mapped by the same key. Note that if an empty collection is provided, the entry for the provided key will not be be explicitly created.

public List<V> remove (K key)

public boolean removeAll (Collection<K> keys)

Remove all entries mapping to the collection of keys.

Similar semantics as removeAll(Collection).

Returns
  • true if the multi-map was modified

public int removeMulti (K key, Collection<? extends V> values, boolean removeEmptyBucket)

public int removeMulti (K key, Collection<? extends V> values)

public V removeValue (K key, V value, boolean removeEmptyBucket)

public V removeValue (K key, V value)

public int size ()

Get the number of key-value mappings (per Map interface). That is, the number of values.

public String toString ()

public Collection<V> values ()