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 int
The 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 TypeMethodDescriptionboolean
Adds a pair to this multimap.final boolean
void
clear()
boolean
Whether this multimap contains a pair with the given components.boolean
Creates 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.boolean
isEmpty()
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.boolean
Removes a pair from this multimap.boolean
boolean
removeAllDomain
(Collection<? extends A> c) Removes all pairs with a left component in the given collection from this multimap.boolean
removeAllRange
(Collection<? extends B> c) Removes all pairs with a right component in the given collection from this multimap.boolean
removeDomain
(A a) Removes all pairs with a given left component from this multimap.boolean
removeRange
(B b) Removes all pairs with a given right component from this multimap.boolean
retainAllDomain
(Collection<? extends A> c) Removes from this multimap all pairs with a left component which is not in the given collection.boolean
retainAllRange
(Collection<? extends B> c) Removes from this multimap all pairs with a right component which is not in the given collection.int
size()
toString()
Returns a string representation of this instance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.function.BiPredicate
and, negate, or
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods 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, toString
Methods 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 thatequals
any 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:Multimap
Removes a pair from this multimap. Removing a pair thatequals
no pair contained in this multimap componentwise must not change this multimap. -
contains
-
contains
Description copied from interface:Multimap
Whether this multimap contains a pair with the given components. -
domain
Description copied from interface:Multimap
Returns 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
removeDomain
operation, then the returned set and its iterators must support theremove
operation, and changes by these operations must be reflected by this multimap. -
range
Description copied from interface:Multimap
Returns 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
removeRange
operation, then the returned set and its iterators must support theremove
operation, and changes by these operations must be reflected by this multimap. -
removeDomain
Description copied from interface:Multimap
Removes 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:
removeDomain
in 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:Multimap
Removes 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:
removeRange
in 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:Multimap
Removes all pairs with a left component in the given collection from this multimap.- Specified by:
removeAllDomain
in 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:Multimap
Removes from this multimap all pairs with a left component which is not in the given collection.- Specified by:
retainAllDomain
in 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:Multimap
Removes all pairs with a right component in the given collection from this multimap.- Specified by:
removeAllRange
in 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:Multimap
Removes from this multimap all pairs with a right component which is not in the given collection.- Specified by:
retainAllRange
in 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:Multimap
Returns 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:Multimap
Convenience method for untyped inquiry.- Specified by:
imageUnchecked
in 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:Multimap
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. The result is backed by the argument. Subsequent changes to either Collection are reflected by the other. -
preimage
Description copied from interface:Multimap
Returns 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:Multimap
Convenience method for untyped inquiry.- Specified by:
preimageUnchecked
in 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: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. The result is backed by the argument. Subsequent changes to either Collection are reflected by the other.- Specified by:
preimageMap
in 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
.
-