Class MapMultimap<A,B>
- Type Parameters:
A- type of the domain elementsB- type of the range elements
- All Implemented Interfaces:
Multimap<A,,B> Serializable,Iterable<Map.Entry<A,,B>> Collection<Map.Entry<A,,B>> BiPredicate<A,,B> Set<Map.Entry<A,B>>
- Direct Known Subclasses:
HashMultimap
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe map from all contained range elements to the set of domain elements which point to it.The map from all contained domain elements to the set of range elements which point to it.protected intThe number of pairs currently realized by this instance.Fields inherited from interface eu.bandm.tools.util.multi.Multimap
DEFAULT_PAIR_FORMAT_STRING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a pair to this multimap.final booleanvoidclear()booleanWhether this multimap contains a pair with the given components.booleanCreates the preimage set for every range element added.Creates the image set for every domain element added.domain()Returns the set of left components of pairs in this multimap.Returns the set of right components of pairs with a given left component in this multimap.imageMap()Returns a map which maps each A which appears as a left component to a set of all B which appear as its right component.Convenience method for untyped inquiry.booleanisEmpty()iterator()Returns the set of left components of pairs with a given right component in this multimap.Returns a map which maps each B which appears as a right component to a set of all A which appear as its left component.Convenience method for untyped inquiry.range()Returns the set of right components of pairs in this multimap.booleanRemoves a pair from this multimap.booleanbooleanremoveAllDomain(Collection<? extends A> c) Removes all pairs with a left component in the given collection from this multimap.booleanremoveAllRange(Collection<? extends B> c) Removes all pairs with a right component in the given collection from this multimap.booleanremoveDomain(A a) Removes all pairs with a given left component from this multimap.booleanremoveRange(B b) Removes all pairs with a given right component from this multimap.booleanretainAllDomain(Collection<? extends A> c) Removes from this multimap all pairs with a left component which is not in the given collection.booleanretainAllRange(Collection<? extends B> c) Removes from this multimap all pairs with a right component which is not in the given collection.intsize()toString()Returns a string representation of this instance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.function.BiPredicate
and, negate, orMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface eu.bandm.tools.util.multi.Multimap
addAll, containsAll, containsUnchecked, imageAll, imageAllUnchecked, preimageAll, preimageAllUnchecked, removeAll, removeAllDomainUnchecked, removeAllRangeUnchecked, removeDomainUnchecked, removeRangeUnchecked, removeUnchecked, retainAll, retainAllDomainUnchecked, retainAllRangeUnchecked, test, toArray, toArray, toString, toStringMethods inherited from interface java.util.Set
equals, hashCode, spliterator
-
Field Details
-
forward
The map from all contained domain elements to the set of range elements which point to it. These sets are never empty. -
backward
The map from all contained range elements to the set of domain elements which point to it. These sets are never empty. -
size
protected int sizeThe number of pairs currently realized by this instance.
-
-
Constructor Details
-
MapMultimap
May not be called by the user. May only called by constructors of subclasses, because all arguments must be in a consistent state.- Parameters:
forward- the map from domain elements to sets of range elements.backward- the map from range elements to sets of domain elements.size- the element pairs contained in the state defined by the given maps.
-
-
Method Details
-
createForwardSet
Creates the image set for every domain element added.Subclasses implementing this method must ensure that when the map A->Set<B> is sorted, then this set also is.
- Returns:
- a sets for range domain elements assigned to one particular domain element.
-
createBackwardSet
Creates the preimage set for every range element added.Subclasses implementing this method must ensure that when the map B->Set<A> is sorted, then this set also is.
- Returns:
- a sets for the domain elements assigned to one particular range element.
-
isEmpty
public boolean isEmpty() -
add
This implementation calls
add(Object,Object), because individual map entries are not used to hold pairs. -
add
Adds a pair to this multimap. This operation must be stable: adding a pair thatequalsany pair contained in this multimap componentwise must not change this multimap.This implementation works directly on internal maps of sets, and is the only way to actually effect the adding. Subclasses should override this method only to impose additional checks.
-
remove
-
remove
Description copied from interface:MultimapRemoves a pair from this multimap. Removing a pair thatequalsno pair contained in this multimap componentwise must not change this multimap. -
contains
-
contains
Description copied from interface:MultimapWhether this multimap contains a pair with the given components. -
domain
Description copied from interface:MultimapReturns the set of left components of pairs in this multimap.The returned set is backed by this multimap, such that changes to this multimap are reflected by the set. The behavior of modifications of this multimap concurrent to iteration of the set is unspecified.
If this multimap supports the
removeDomainoperation, then the returned set and its iterators must support theremoveoperation, and changes by these operations must be reflected by this multimap. -
range
Description copied from interface:MultimapReturns the set of right components of pairs in this multimap.The returned set is backed by this multimap, such that changes to this multimap are reflected by the set. The behavior of modifications of this multimap concurrent to iteration of the set is unspecified.
If this multimap supports the
removeRangeoperation, then the returned set and its iterators must support theremoveoperation, and changes by these operations must be reflected by this multimap. -
removeDomain
Description copied from interface:MultimapRemoves all pairs with a given left component from this multimap. The effect of the implementation on this multimap must be equivalent to the following code:removeDomain(final A a) { for (B b : new HashSet<B>(range())) remove(a, b) ; }- Specified by:
removeDomainin interfaceMultimap<A,B> - Parameters:
a- the left component of all pairs to remove.- Returns:
- whether this multimap has been changed by this operation
-
removeRange
Description copied from interface:MultimapRemoves all pairs with a given right component from this multimap. The effect of the implementation on this multimap must be equivalent to the following code:removeRange(final B b) { for (A a : new HashSet<A>(domain())) remove(a, b) ; }- Specified by:
removeRangein interfaceMultimap<A,B> - Parameters:
b- the right component of all pairs to remove.- Returns:
- whether this multimap has been changed by this operation
-
removeAllDomain
Description copied from interface:MultimapRemoves all pairs with a left component in the given collection from this multimap.- Specified by:
removeAllDomainin interfaceMultimap<A,B> - Parameters:
c- the set of left component of all pairs to remove.- Returns:
- whether this multimap has been changed by this operation
-
retainAllDomain
Description copied from interface:MultimapRemoves from this multimap all pairs with a left component which is not in the given collection.- Specified by:
retainAllDomainin interfaceMultimap<A,B> - Parameters:
c- the set of left component of all pairs not to remove.- Returns:
- whether this multimap has been changed by this operation
-
removeAllRange
Description copied from interface:MultimapRemoves all pairs with a right component in the given collection from this multimap.- Specified by:
removeAllRangein interfaceMultimap<A,B> - Parameters:
c- the set of the right component of all pairs to remove.- Returns:
- whether this multimap has been changed by this operation
-
retainAllRange
Description copied from interface:MultimapRemoves from this multimap all pairs with a right component which is not in the given collection.- Specified by:
retainAllRangein interfaceMultimap<A,B> - Parameters:
c- the set of the right component of all pairs not emove.- Returns:
- whether this multimap has been changed by this operation
-
image
Description copied from interface:MultimapReturns the set of right components of pairs with a given left component in this multimap.The returned set need not be modifiable. The behaviour of this multimap after successfully modifying the returned set is unspecified.
-
imageUnchecked
Description copied from interface:MultimapConvenience method for untyped inquiry.- Specified by:
imageUncheckedin interfaceMultimap<A,B> - Parameters:
a- a left component.- Returns:
- the set of right components of pairs with a left
component that
equals(a)in this multimap. - See Also:
-
imageMap
Description copied from interface:MultimapReturns a map which maps each A which appears as a left component to a set of all B which appear as its right component. The result is backed by the argument. Subsequent changes to either Collection are reflected by the other. -
preimage
Description copied from interface:MultimapReturns the set of left components of pairs with a given right component in this multimap.The returned set need not be modifiable. The behaviour of this multimap after successfully modifying the returned set is unspecified.
-
preimageUnchecked
Description copied from interface:MultimapConvenience method for untyped inquiry.- Specified by:
preimageUncheckedin interfaceMultimap<A,B> - Parameters:
b- a right component.- Returns:
- the set of left components of pairs with a right
component that
equals(b)in this multimap. - See Also:
-
preimageMap
Description copied from interface:MultimapReturns a map which maps each B which appears as a right component to a set of all A which appear as its left component. The result is backed by the argument. Subsequent changes to either Collection are reflected by the other.- Specified by:
preimageMapin interfaceMultimap<A,B> - Returns:
- a map which maps each B which appears as a right component to a set of all A which appear as its left component.
-
clear
public void clear() -
size
public int size() -
iterator
-
toString
Returns a string representation of this instance. CallsMultimap.toString(String)withMultimap.DEFAULT_PAIR_FORMAT_STRING.
-