Class AbstractMultimap<A,B>
- Type Parameters:
A
- type of the domain elementsB
- type of the range elements
- All Implemented Interfaces:
Multimap<A,
,B> Iterable<Map.Entry<A,
,B>> Collection<Map.Entry<A,
,B>> BiPredicate<A,
,B> Set<Map.Entry<A,
B>>
To implement an unmodifiable multimap, subclasses need only to implement
the methods AbstractCollection.iterator()
and AbstractCollection.size()
.
To implement a modifiable collection, subclasses must also override the
method AbstractCollection.add(Object)
, and the iterators return by AbstractCollection.iterator()
must override the method Iterator.remove()
.
Subclasses that do not use Map.Entry
objects for internal storage
are encouraged to override the methods add(Object,Object)
, remove(Object,Object)
, contains(Object,Object)
, Multimap.removeUnchecked(Object,Object)
and Multimap.containsUnchecked(Object,Object)
.
Every subclass should define a copying constructor.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final AbstractMultimap
<A, B> For to make "this" accessible by deeply nested anonymous classes.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 if not already present.boolean
Whether this multimap contains a pair with the given components.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.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.toString()
Returns a string representation of this instance.Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
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, removeAllDomain, removeAllDomainUnchecked, removeAllRange, removeAllRangeUnchecked, removeDomain, removeDomainUnchecked, removeRange, removeRangeUnchecked, removeUnchecked, retainAll, retainAllDomain, retainAllDomainUnchecked, retainAllRange, retainAllRangeUnchecked, test, toArray, toArray, toString, toString
-
Field Details
-
abstractMultimap
For to make "this" accessible by deeply nested anonymous classes.
-
-
Constructor Details
-
AbstractMultimap
protected AbstractMultimap()Creates a new instance.
-
-
Method Details
-
add
Adds a pair to this multimap if not already present.The default implementation calls
AbstractCollection.add(E)
with a newly created map entry to hold the pair. Subclasses may override this method for a more efficient implementation. -
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
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. -
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.
-
toString
Returns a string representation of this instance. CallsMultimap.toString(String)
withMultimap.DEFAULT_PAIR_FORMAT_STRING
.- Overrides:
toString
in classAbstractCollection<Map.Entry<A,
B>>
-