edu.rice.cs.plt.collect
Class ExternallySortedMultiMap<K,V,C extends Comparable<? super C>>

java.lang.Object
  extended by edu.rice.cs.plt.collect.ExternallySortedMultiMap<K,V,C>

public class ExternallySortedMultiMap<K,V,C extends Comparable<? super C>>
extends Object

Maps from a key to a set of values; a key may be added multiple times with different values, and those values are collected in a set. Each set is ordered according to some Comparable corresponding to each value. The methods provided are modeled after the Map interface. However, the container being modeled is not exactly a map, and some of the Map methods do not make sense in this context. For example, put(key, value) was replaced here by put(key, value, orderBy).


Constructor Summary
ExternallySortedMultiMap()
          Create an empty map.
 
Method Summary
 void clear()
          Removes all elements from the map.
 boolean contains(K key, V value)
           
 boolean containsKey(K key)
           
 boolean containsValue(V value)
           
 Iterable<V> get(K key)
           
 boolean isEmpty()
           
 Iterable<K> keys()
           
 boolean put(K key, V value, C orderBy)
          Adds the (key, value) pair if it is not already present.
 boolean putAll(ExternallySortedMultiMap<? extends K,? extends V,? extends C> map)
          Adds all (key, value) pairs represented by map to this map.
 boolean remove(K key, V value)
          Removes the (key, value) pair if it is present.
 boolean removeKey(K key)
          Removes all values associated with the specified key.
 int size()
           
 int size(int bound)
           
 Iterable<V> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExternallySortedMultiMap

public ExternallySortedMultiMap()
Create an empty map.

Method Detail

size

public int size()
Returns:
The current number of (key, value) pairs in the map.

size

public int size(int bound)
Returns:
The current number of (key, value) pairs in the map, or bound if it is less.

isEmpty

public boolean isEmpty()
Returns:
true iff size() == 0.

containsKey

public boolean containsKey(K key)
Returns:
true iff the specified key is mapped to at least 1 value.

containsValue

public boolean containsValue(V value)
Returns:
true iff the specified value is associated with some key.

contains

public boolean contains(K key,
                        V value)
Returns:
true iff the specified (key, value) pair is in the map.

get

public Iterable<V> get(K key)
Returns:
A dynamically-updated view of the values associated with the given key, sorted by their corresponding orderBy values. If the key maps to no values when Iterable.iterator() is invoked, a 0-length iterator is returned. Iterator.remove() is not supported.

put

public boolean put(K key,
                   V value,
                   C orderBy)
Adds the (key, value) pair if it is not already present.

Returns:
true iff the (key, value) pair is not already present in the map.

remove

public boolean remove(K key,
                      V value)
Removes the (key, value) pair if it is present.

Returns:
true iff the (key, value) pair was present in (and thus removed from) the map.

removeKey

public boolean removeKey(K key)
Removes all values associated with the specified key.

Returns:
true iff the operation modifies the map.

putAll

public boolean putAll(ExternallySortedMultiMap<? extends K,? extends V,? extends C> map)
Adds all (key, value) pairs represented by map to this map. If a mapping is already present, adding it makes no modifications; otherwise, the pair is added, sorted according to the orderBy value in map.

Returns:
true iff the operation modified the map.

clear

public void clear()
Removes all elements from the map.


keys

public Iterable<K> keys()
Returns:
A dynamically-updating iterable of all keys associated with at least one value in this map. Iterator.remove() is not supported.

values

public Iterable<V> values()
Returns:
A dynamically-updating iterable of all values associated with any key in this map. Iterator.remove() is not supported.