Interface Multimap<A,B>
- Type Parameters:
A- type of the domain elementsB- type of the range elements
- All Superinterfaces:
BiPredicate<A,,B> Collection<Map.Entry<A,,B>> Iterable<Map.Entry<A,,B>> Set<Map.Entry<A,B>>
- All Known Subinterfaces:
SortedMultimap<A,B>
- All Known Implementing Classes:
AbstractMultimap,HashMultimap,MapMultimap,UnmodifiableMultimap
Map.Entry. The object returned by getKey() is called the left component
of the pair; the object returned by getValue() is called the right component of the
pair.
null components are not supported.
Implementations should fail early when the user tries to add null,
by IllegalArgumentException or NullPointerException.
Implementations need not guarantee that null values are never observed.
The effect of attempting to change the right component by
invoking setValue on a pair is
unspecified. Implementations may either prohibit the operation by
throwing UnsupportedOperationException or allow the
operation but behave in an unspecified way afterwards.
Pairs in a multimap are considered equal if and only if both
their left and right components are equal according to their
respective equals methods. Such pairs are said to be equal
componentwise. The implementations of Map.Entry
returned by implementations must implement equals and
hashCode accordingly.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringA format string for the string representation of contained entries. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a pair to this multimap.default booleanaddAll(Collection<? extends Map.Entry<A, B>> c) booleanWhether this multimap contains a pair with the given components.default booleancontainsAll(Collection<?> c) default booleancontainsUnchecked(Object a, Object b) Convenience method for untyped inquiry.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.imageAll(Collection<? extends A> c) Returns the set of right components of pairs in this multimap which have a left component in the given set.imageAllUnchecked(Collection<?> c) Convenience method for untyped inquiry.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.preimageAll(Collection<? extends B> c) Returns the set of left components of pairs in this multimap which have a right component in the given set.Convenience method for untyped inquiry.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.default booleanremoveAll(Collection<?> data) default booleanremoveAllDomain(Collection<? extends A> c) Removes all pairs with a left component in the given collection from this multimap.default booleanConvenience method for untyped remove.default booleanremoveAllRange(Collection<? extends B> c) Removes all pairs with a right component in the given collection from this multimap.default booleanConvenience method for untyped remove.default booleanremoveDomain(A a) Removes all pairs with a given left component from this multimap.default booleanConvenience method for untyped remove.default booleanremoveRange(B b) Removes all pairs with a given right component from this multimap.default booleanConvenience method for untyped remove.default booleanremoveUnchecked(Object a, Object b) Convenience method for untyped remove.default booleanretainAll(Collection<?> data) default booleanretainAllDomain(Collection<? extends A> c) Removes from this multimap all pairs with a left component which is not in the given collection.default booleanConvenience method for untyped remove.default booleanretainAllRange(Collection<? extends B> c) Removes from this multimap all pairs with a right component which is not in the given collection.default booleanConvenience method for untyped remove.default booleandefault Object[]toArray()default <T> T[]toArray(T[] proto) default StringReturns a string representation of this instance.default StringtoString(BiFunction<? super A, ? super B, String> pairToString) Returns a string representation of this instance.Methods inherited from interface java.util.function.BiPredicate
and, negate, orMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Field Details
-
DEFAULT_PAIR_FORMAT_STRING
A format string for the string representation of contained entries.- See Also:
-
-
Method Details
-
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.- Parameters:
a- the left component of the pair to addb- the right component of the pair to add- Returns:
- whether this multimap has been changed by this operation
- Throws:
NullPointerException- (optionally) ifaorbisnullIllegalArgumentException- (optionally) ifaorbisnull
-
contains
Whether this multimap contains a pair with the given components.- Parameters:
a- the left component of the pair to add.b- the right component of the pair to add.- Returns:
- whether this multimap contains a pair with the given components.
-
test
- Specified by:
testin interfaceBiPredicate<A,B>
-
containsUnchecked
Convenience method for untyped inquiry.- Parameters:
a- the left component of the pair to testb- the right component of the pair to test- Returns:
- whether this multimap contains a pair with the given components.
- See Also:
-
remove
Removes a pair from this multimap. Removing a pair thatequalsno pair contained in this multimap componentwise must not change this multimap.- Parameters:
a- the left component of the pair to remove.b- the right component of the pair to remove.- Returns:
- whether this multimap has been changed by this operation
- Throws:
NullPointerException- (optionally) ifaorbisnull.IllegalArgumentException- (optionally) ifaorbisnull.
-
removeUnchecked
Convenience method for untyped remove.- Parameters:
a- the left component of the pair to remove.b- the right component of the pair to remove.- Returns:
- whether this multimap has been changed by this operation
- See Also:
-
removeAll
-
retainAll
-
removeDomain
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) ; }- Parameters:
a- the left component of all pairs to remove.- Returns:
- whether this multimap has been changed by this operation
- Throws:
NullPointerException- (optionally) ifaisnull.IllegalArgumentException- (optionally) ifaisnull.
-
removeDomainUnchecked
Convenience method for untyped remove.- Parameters:
a- the left component of all pairs to remove.- Returns:
- whether this multimap has been changed by this operation
- See Also:
-
removeAllDomain
Removes all pairs with a left component in the given collection from this multimap.- Parameters:
c- the set of left component of all pairs to remove.- Returns:
- whether this multimap has been changed by this operation
-
removeAllDomainUnchecked
Convenience method for untyped remove.- Parameters:
c- the set of left component of all pairs to remove.- Returns:
- whether this multimap has been changed by this operation
- See Also:
-
retainAllDomain
Removes from this multimap all pairs with a left component which is not in the given collection.- Parameters:
c- the set of left component of all pairs not to remove.- Returns:
- whether this multimap has been changed by this operation
-
retainAllDomainUnchecked
Convenience method for untyped remove.- Parameters:
c- the set of left component of all pairs not to remove.- Returns:
- whether this multimap has been changed by this operation
- See Also:
-
removeRange
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) ; }- Parameters:
b- the right component of all pairs to remove.- Returns:
- whether this multimap has been changed by this operation
- Throws:
NullPointerException- (optionally) ifbisnull.IllegalArgumentException- (optionally) ifbisnull.
-
removeRangeUnchecked
Convenience method for untyped remove. Removes all pairs with a given right component from this multimap.- Parameters:
b- the right component of all pairs to remove.- Returns:
- whether this multimap has been changed by this operation
- See Also:
-
removeAllRange
Removes all pairs with a right component in the given collection from this multimap.- Parameters:
c- the set of the right component of all pairs to remove.- Returns:
- whether this multimap has been changed by this operation
-
removeAllRangeUnchecked
Convenience method for untyped remove. Removes all pairs with a right component in the given collection from this multimap.- Parameters:
c- the set of the right component of all pairs to remove.- Returns:
- whether this multimap has been changed by this operation
- See Also:
-
retainAllRange
Removes from this multimap all pairs with a right component which is not in the given collection.- Parameters:
c- the set of the right component of all pairs not emove.- Returns:
- whether this multimap has been changed by this operation
-
retainAllRangeUnchecked
Convenience method for untyped remove. Removes all pairs with a right component which is not the given collection from this multimap.- Parameters:
c- the set of the right component of all pairs not emove.- Returns:
- whether this multimap has been changed by this operation
- See Also:
-
addAll
-
containsAll
- Specified by:
containsAllin interfaceCollection<A>- Specified by:
containsAllin interfaceSet<A>
-
toArray
default <T> T[] toArray(T[] proto) -
toArray
-
domain
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
removeDomainoperation, then the returned set and its iterators must support theremoveoperation, and changes by these operations must be reflected by this multimap.- Returns:
- the set of left components of pairs in this multimap.
-
range
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
removeRangeoperation, then the returned set and its iterators must support theremoveoperation, and changes by these operations must be reflected by this multimap.- Returns:
- the set of right components of pairs in this multimap.
-
image
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.
- Parameters:
a- a left component.- Returns:
- the set of right components of pairs with a left
component that
equals(a)in this multimap. - Throws:
NullPointerException- ifaisnull.IllegalArgumentException- ifaisnull.
-
imageUnchecked
Convenience method for untyped inquiry.- 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:
-
imageAll
Returns the set of right components of pairs in this multimap which have a left component in the given set.- Parameters:
c- a set of left components.- Returns:
- the set of right components of pairs with a left component in the given set.
-
imageAllUnchecked
Convenience method for untyped inquiry.- Parameters:
c- a set of left components.- Returns:
- the set of right components of pairs with a left component in the given set.
- See Also:
-
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. The result is backed by the argument. Subsequent changes to either Collection are reflected by the other.- 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.
-
preimage
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.
- Parameters:
b- a right component.- Returns:
- the set of left components of pairs with a right
component that
equals(b)in this multimap. - Throws:
NullPointerException- ifbisnull.IllegalArgumentException- ifbisnull.
-
preimageUnchecked
Convenience method for untyped inquiry.- Parameters:
b- a right component.- Returns:
- the set of left components of pairs with a right
component that
equals(b)in this multimap. - Throws:
NullPointerException- ifbisnull.IllegalArgumentException- ifbisnull.- See Also:
-
preimageAll
Returns the set of left components of pairs in this multimap which have a right component in the given set.- Parameters:
c- a set of right components.- Returns:
- the set of left components of pairs with a right component in the given set.
- Throws:
NullPointerException- ifbisnull.IllegalArgumentException- ifbisnull.
-
preimageAllUnchecked
Convenience method for untyped inquiry.- Parameters:
c- a set of right components.- Returns:
- the set of left components of pairs with a right component in the given set.
- See Also:
-
preimageMap
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.- 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.- Parameters:
pairFormatString- a format string applied to key and value of all contained entries.- Returns:
- a string representation of this instance.
-
toString
Returns a string representation of this instance.- Parameters:
pairToString- a function to get the string representation of all contained entries.- Returns:
- a string representation of this instance.
-