com.aliasi.util
Class ObjectToSet<K,M>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,Set<M>>
          extended by com.aliasi.util.ObjectToSet<K,M>
Type Parameters:
K - the type of keys for this mapping
M - the type of members stored in the value sets for this map
All Implemented Interfaces:
Serializable, Cloneable, Map<K,Set<M>>

public class ObjectToSet<K,M>
extends HashMap<K,Set<M>>

An ObjectToSet provides a Map from arbitrary objects to objects of class Set. In addition to methods inherited from Map, there are methods to add members to a set value and get set values directly.

Since:
LingPipe1.0
Version:
3.8
Author:
Bob Carpenter
See Also:
Serialized Form

Constructor Summary
ObjectToSet()
          Construct a new object to set mapping.
 
Method Summary
 void addMember(K key, M member)
          Add a member to the value of the set mapped to by the specified key.
 void addMembers(K key, Set<? extends M> values)
          Adds a set of members to the value of the set mapped to by the specified key.
 Set<M> getSet(K key)
          Returns the set of values for the specified key, or the empty set if there have been none added.
 Iterator<M> memberIterator()
          Returns an iterator over all values.
 Set<M> memberValues()
          Returns a set constituting the union of all of the members of the set values for all of the keys.
 boolean removeMember(K key, M member)
          Removes the specified value from the set of values assigned to the specified key.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

ObjectToSet

public ObjectToSet()
Construct a new object to set mapping.

Method Detail

addMember

public void addMember(K key,
                      M member)
Add a member to the value of the set mapped to by the specified key.

Parameters:
key - Key whose set value will have the object.
member - Object to add to the value of the key.

removeMember

public boolean removeMember(K key,
                            M member)
Removes the specified value from the set of values assigned to the specified key. If it is the last key, it removes the mapping altogether.

Parameters:
key - Key whose members will have the value removed.
member - Value to remove from the set of members assigned to the key.
Returns:
true if the value was in the set of members for the key.

addMembers

public void addMembers(K key,
                       Set<? extends M> values)
Adds a set of members to the value of the set mapped to by the specified key.

Parameters:
key - Key whose set value will have the object.
values - Values to add to the set picked out by the key.

memberValues

public Set<M> memberValues()
Returns a set constituting the union of all of the members of the set values for all of the keys.

Returns:
The union of the members of the set values.

getSet

public Set<M> getSet(K key)
Returns the set of values for the specified key, or the empty set if there have been none added. This behavior only differs from the basic HashMap.get(Object) method in that it returns the empty set rather than null.


memberIterator

public Iterator<M> memberIterator()
Returns an iterator over all values. The values will not necessarily be unique if they are members of the set of values for different keys. Each member of the set memberValues() will be returned at least once through this iteration.

Returns:
An iterator over the individual members of the set values.