K - the type of keys for this mappingM - the type of members stored in the value sets for this
mappublic class ObjectToSet<K,M> extends HashMap<K,Set<M>>
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.AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Constructor and Description |
|---|
ObjectToSet()
Construct a new object to set mapping.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesequals, hashCode, toStringpublic void addMember(K key, M member)
key - Key whose set value will have the object.member - Object to add to the value of the key.public boolean removeMember(K key, M member)
key - Key whose members will have the value removed.member - Value to remove from the set of members assigned
to the key.true if the value was in the set of
members for the key.public void addMembers(K key, Set<? extends M> values)
key - Key whose set value will have the object.values - Values to add to the set picked out by the key.public Set<M> memberValues()
public Set<M> getSet(K key)
HashMap.get(Object) method in that it returns the
empty set rather than null.public Iterator<M> memberIterator()
memberValues()
will be returned at least once through this iteration.Copyright © 2019 Alias-i, Inc.. All rights reserved.