Package eu.bandm.tools.util.multi
Class Multimaps
java.lang.Object
eu.bandm.tools.util.multi.Multimaps
Utility class of constants and combinators for
Multimap
.-
Method Summary
Modifier and TypeMethodDescriptionstatic <A,
B> Multimap <A, B> Returns an unmodifiable multimap that contains all combinations of the given elements.static <A,
B> Multimap <A, B> Returns an unmodifiable multimap that contains all combinations of the given elements.static <A,
B> Multimap <A, B> Returns an unmodifiable multimap that contains all combinations of the given elements.static <A,
B> Multimap <A, B> asMultimap
(Set<Map.Entry<A, B>> things) Returns a multimap view of the given set of map entries.static <A,
B> Multimap <B, A> Returns a multimap view on the entry set of a map, from its range to its domain.static <A> Comparator
<A> cache
(Comparator<? super A> c) Cache comparator results.static <A,
B> Map <A, B> Returns an unmodifiable map which assigns to every element of the domain some arbitrary element of its image.static <A> Multimap
<A, A> Returns a multimap which is a composition of arbitrary many multimaps, all of the same type.static <A,
B, C> HashMultimap <A, C> Returns a hash multimap which corresponds to the composition of the corresponding relations.static <A,
B, C, D>
Multimap<A, D> Returns a multimap which corresponds to the composition of three multimaps.static <A,
B, C, D, E>
Multimap<A, E> Returns a multimap which corresponds to the composition of four multimaps.static <A,
B, C, D, E, F>
Multimap<A, F> Returns a multimap which corresponds to the composition of five multimaps.static <A,
B, C, R extends Multimap<? super A, ? super C>>
RReturns a multimap which corresponds to the composition of the corresponding relations.static <A,
R extends Multimap<A, A>>
RReturns a multimap which is a composition of arbitrary many multimaps, all of the same type.static <A,
B, C, D>
Multimap<A, D> Returns a multimap which corresponds to the composition of three multimaps.static <A,
B, C, D, E>
Multimap<A, E> compose
(Supplier<Multimap> newInstance, Multimap<A, B> r, Multimap<B, C> s, Multimap<C, D> t, Multimap<D, E> u) Returns a multimap which corresponds to the composition of four multimaps.static <A,
B, C, D, E, F>
Multimap<A, F> compose
(Supplier<Multimap> newInstance, Multimap<A, B> r, Multimap<B, C> s, Multimap<C, D> t, Multimap<D, E> u, Multimap<E, F> v) Returns a multimap which corresponds to the composition of five multimaps.static <A,
B, C> Multimap <A, C> Deprecated, for removal: This API element is subject to removal in a future version.static <A,
B> Multimap <B, A> Returns an unmodifiable view to the argument where left component and right component of every contained pair are exchanged.static <A,
B> Multimap <A, B> empty()
Returns an unmodifiable multimap which is empty.static <A,
B> Multimap <A, B> Returns a multimap view on the entry set of a map.static <A> Multimap
<A, A> Returns a modifiable multimap which realizes the id1entity relation of all elements from the given set.static <A,
B> Map <A, B> Adds the pairs from a Multimap into a Map, if possible.static <A,
B> Multimap <B, A> Deprecated, for removal: This API element is subject to removal in a future version.useconverse(eu.bandm.tools.util.multi.Multimap<A, B>)
instead.static <A,
B, C, D>
Multimap<C, D> map
(Function<? super A, ? extends C> left, Function<? super B, ? extends D> right, Multimap<? extends A, ? extends B> gen) Returns a new multimap the pairs of which combine the results of applying two functions to the two sides of the pairs in the given multimap.static <A,
B, C, D, R extends Multimap<C, D>>
Rmap
(Supplier<R> newInstance, Function<? super A, ? extends C> left, Function<? super B, ? extends D> right, Multimap<? extends A, ? extends B> gen) Returns a new multimap the pairs of which combine the results of applying two functions to the two sides of the pairs in the given multimap.static <A,
B> Multimap <A, B> maxMatching
(Multimap<A, B> rel) Find a maximum bijective function which is contained in the given relation.static <A> boolean
reflexiveClosure
(Multimap<A, A> r) Modifies the argument to contain all identity pairs of all contained elements.static <A> boolean
reflexiveClosure
(Multimap<A, A> r, Set<? extends A> s) Modifies the argument to contain all identity pairs of elements given explicitly in the set argument.static <A> boolean
reflexiveReduction
(Multimap<A, A> r) Modifies the argument to not contain an identity pair of any contained element.static <A> boolean
reflexiveReduction
(Multimap<A, A> r, Set<? extends A> s) Modifies the argument to not contain an identity pair of the explicitly given elements.static <A,
B> Multimap <A, B> singleton
(A a, B b) Returns an unmodifiable multimap which contains only the given pair.static <A,
B> Multimap <A, B> slice
(BiPredicate<? super A, ? super B> r, Set<? extends A> dom, Set<? extends B> ran) Returns a new multimap which contains all pairs from the given sets which fulfill the given predicate.static <A,
B, R extends Multimap<A, B>>
Rslice
(Supplier<R> newInstance, BiPredicate<? super A, ? super B> r, Set<? extends A> dom, Set<? extends B> ran) Returns a new multimap which contains all pairs from the given sets which fulfill the given predicate.static <A,
B, C> Multimap <B, C> span
(Function<? super A, ? extends B> left, Function<? super A, ? extends C> right, Collection<? extends A> gen) Returns a multimap the pairs of which combine the results of applying two functions to the elements of a given collection.static <A,
B, C, R extends Multimap<B, C>>
Rspan
(Supplier<R> newInstance, Function<? super A, ? extends B> left, Function<? super A, ? extends C> right, Collection<? extends A> gen) Returns a multimap the pairs of which combine the results of applying two functions to the elements of a given collection.static <A> Set
<A> Returns a set of all elements appearing on any side of the multimap.static <A> boolean
symmetricClosure
(Multimap<A, A> r) Modifies the argument by adding to each pair also the inverse.static <A,
B, C> Multimap <B, C> toSpan
(Function<? super A, ? extends B> left, Function<? super A, ? extends C> right, Collection<? extends A> gen) Deprecated, for removal: This API element is subject to removal in a future version.static <A,
B> Multimap <A, B> toSum
(Collection<? extends A> dom, Function<? super A, ? extends Collection<? extends B>> fun) Collect all combinations which result from applying the given set-valued function to all elements of the given collection.static <A,
B, R extends Multimap<A, B>>
RtoSum
(Supplier<R> newInstance, Collection<? extends A> dom, Function<? super A, ? extends Collection<? extends B>> fun) Collect all combinations which result from applying the given set-valued function to all elements of the given collection.static <A> Multimap
<A, A> toSymmetricClosure
(Multimap<A, A> r) Returns a new multimap which contains the given argument and its inversion.static <A> Multimap
<A, A> toTransitiveClosure
(Multimap<A, A> r) Returns a new multimap which contains the transitive closure of the argument.static <A,
R extends Multimap<A, A>>
RtoTransitiveClosure
(Supplier<? extends R> newInstance, Multimap<A, A> r) Returns a new multimap which contains the transitive closure of the argument.static <A> boolean
transitiveClosure
(Multimap<A, A> r) Modifies the argument by adding each pair which can be constructed by composing two or more pairs.static <A> boolean
transitiveClosureSparse
(Multimap<A, A> r) Modifies the argument by adding each pair which can be constructed by composing two or more pairs.static <A,
B> Multimap <A, B> unmodifiableMultimap
(Multimap<? extends A, ? extends B> m) Returns a wrapper round the argument which does not allow modifications.
-
Method Details
-
cache
Cache comparator results.- Type Parameters:
A
- the type of elements to be compared.- Parameters:
c
- the comparator the results of which will be cached- Returns:
- a comparator which caches its result in a multimap which is the extension of the "less or equal" relation.
-
intoMap
Adds the pairs from a Multimap into a Map, if possible.- Type Parameters:
A
- the domain of map and multimapB
- the range of map and multimap- Parameters:
in
- MultiMap to copy to the mapout
- Map which is updated. Needs not be empty.- Returns:
- the output map
- Throws:
RuntimeException
- iff the contents of in plus out do not represent a map in the mathematical sense.
-
empty
Returns an unmodifiable multimap which is empty.- Type Parameters:
A
- the domain type of the multimapB
- the range type of the multimap- Returns:
- an unmodifiable multimap which is empty.
-
singleton
Returns an unmodifiable multimap which contains only the given pair.- Type Parameters:
A
- the domain type of the multimapB
- the range type of the multimap- Parameters:
a
- the domain element of the contained pairb
- the range element of the contained pair- Returns:
- an unmodifiable multimap which contains only the given pair
-
id
Returns a modifiable multimap which realizes the id1entity relation of all elements from the given set. This is based onObject.equals(java.lang.Object)
, not on object identity. The map is backed by the set. Changes to either collection are reflected by the other.- Type Parameters:
A
- the type of all elements from the set and range and domain of the multimap- Parameters:
support
- the set of all elements to appear in the result- Returns:
- multimap which realizes the identity of all elements from the given set.
-
all
Returns an unmodifiable multimap that contains all combinations of the given elements. The result is backed by the arguments: changes to the set argument will be reflected by the multimap.- Type Parameters:
A
- the domain type of the multimapB
- the range type of the multimap- Parameters:
dom
- the domain of the multimapran
- the range of the multimap- Returns:
- the multimap of all combinations.
-
all
Returns an unmodifiable multimap that contains all combinations of the given elements. The result is backed by the arguments: changes to the set argument will be reflected by the multimap.- Type Parameters:
A
- the domain type of the multimapB
- the range type of the multimap- Parameters:
dom
- the domain of the multimapran
- the range of the multimap- Returns:
- the multimap of all combinations.
-
all
Returns an unmodifiable multimap that contains all combinations of the given elements. The result is backed by the arguments: changes to the arguments will be reflected by the multimap.- Type Parameters:
A
- the domain type of the multimapB
- the range type of the multimap- Parameters:
dom
- the domain of the multimapran
- the range of the multimap- Returns:
- the multimap of all combinations.
-
inverse
Deprecated, for removal: This API element is subject to removal in a future version.useconverse(eu.bandm.tools.util.multi.Multimap<A, B>)
instead.Returns an unmodifiable view to the argument where left component and right component of every contained pair are exchanged.- Type Parameters:
A
- the domain type of the given multimap and the range type of the resultB
- the range type of the given multimap and the domain type of the result- Parameters:
r
- the map to invert- Returns:
- an unmodifiable multimap which is the inverted given multimap
-
converse
Returns an unmodifiable view to the argument where left component and right component of every contained pair are exchanged. The returned multimap is backed by the given multimap: Changes to the argument are reflected by the result.- Type Parameters:
A
- the domain type of the given multimap and the range type of the resultB
- the range type of the given multimap and the domain type of the result- Parameters:
r
- the map to invert- Returns:
- an unmodifiable multimap which is the inverted given multimap
-
composeAs
@Deprecated(forRemoval=true) public static <A,B, Multimap<A,C> C> composeAs(Multimap<A, B> r, Multimap<B, C> s, Multimap<A, C> result) Deprecated, for removal: This API element is subject to removal in a future version.usecompose(Multimap,Multimap)
instead.Add the composition of the two given multimaps to the multimap given as result.- Type Parameters:
A
- the domain type of the first multimap and of the resultB
- the range type of the first multimap and of the domain of the secondC
- the range type of the second multimap and of the result- Parameters:
r
- the first multimap to composes
- the second multimap to composeresult
- where to add the calculted pairs- Returns:
- the multimap given as result
-
compose
public static <A,B, R composeC, R extends Multimap<? super A, ? super C>> (Supplier<? extends R> newInstance, Multimap<A, B> r, Multimap<B, C> s) Returns a multimap which corresponds to the composition of the corresponding relations. FIXME bt sprachregelung: The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the domain type of the first multimap and of the resultB
- the range type of the first multimap and of the domain of the secondC
- the range type of the second multimap and of the resultR
- the class of the result- Parameters:
newInstance
- a factory method (no parameters) to construct the resultr
- the first multimap to composes
- the second multimap to compose- Returns:
- the new multimap representing the relation composition
-
compose
Returns a hash multimap which corresponds to the composition of the corresponding relations. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the domain type of the first multimap and of the resultB
- the range type of the first multimap and of the domain of the secondC
- the range type of the second multimap and of the result- Parameters:
r
- the first multimap to composes
- the second multimap to compose- Returns:
- the new multimap representing the relation composition
-
compose
Returns a multimap which corresponds to the composition of three multimaps. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the domain of the first multimapB
- the range of the first multimap and the domain of the second multimapC
- the range of the second multimap and the domain of the third multimapD
- the range of the third multimap- Parameters:
r
- the first multimaps
- the second multimapt
- the third multimap- Returns:
- a multimap which corresponds to the composition of the three relations
- See Also:
-
compose
public static <A,B, Multimap<A,C, D> D> compose(Supplier<Multimap> newInstance, Multimap<A, B> r, Multimap<B, C> s, Multimap<C, D> t) Returns a multimap which corresponds to the composition of three multimaps. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the domain of the first multimapB
- the range of the first multimap and the domain of the second multimapC
- the range of the second multimap and the domain of the third multimapD
- the range of the third multimap- Parameters:
newInstance
- a factory method (no parameters) to construct the resultr
- the first multimaps
- the second multimapt
- the third multimap- Returns:
- a multimap which corresponds to the composition of the three relations
- See Also:
-
compose
public static <A,B, Multimap<A,C, D, E> E> compose(Multimap<A, B> r, Multimap<B, C> s, Multimap<C, D> t, Multimap<D, E> u) Returns a multimap which corresponds to the composition of four multimaps. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the domain of the first multimapB
- the range of the first multimap and the domain of the second multimapC
- the range of the second multimap and the domain of the third multimapD
- the range of the third multimap and the domain of the fourth multimapE
- the range of the fourth multimap- Parameters:
r
- the first multimaps
- the second multimapt
- the third multimapu
- the fourth multimap- Returns:
- a multimap which corresponds to the composition of the four relations
- See Also:
-
compose
public static <A,B, Multimap<A,C, D, E> E> compose(Supplier<Multimap> newInstance, Multimap<A, B> r, Multimap<B, C> s, Multimap<C, D> t, Multimap<D, E> u) Returns a multimap which corresponds to the composition of four multimaps. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the domain of the first multimapB
- the range of the first multimap and the domain of the second multimapC
- the range of the second multimap and the domain of the third multimapD
- the range of the third multimap and the domain of the fourth multimapE
- the range of the fourth multimap- Parameters:
newInstance
- a factory method (no parameters) to construct the resultr
- the first multimaps
- the second multimapt
- the third multimapu
- the fourth multimap- Returns:
- a multimap which corresponds to the composition of the four relations
- See Also:
-
compose
public static <A,B, Multimap<A,C, D, E, F> F> compose(Multimap<A, B> r, Multimap<B, C> s, Multimap<C, D> t, Multimap<D, E> u, Multimap<E, F> v) Returns a multimap which corresponds to the composition of five multimaps. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the domain of the first multimapB
- the range of the first multimap and the domain of the second multimapC
- the range of the second multimap and the domain of the third multimapD
- the range of the third multimap and the domain of the fourth multimapE
- the range of the fourth multimap and the domain of the fifth multimapF
- the range of the fifth multimap- Parameters:
r
- the first multimaps
- the second multimapt
- the third multimapu
- the fourth multimapv
- the fifth multimap- Returns:
- a multimap which corresponds to the composition of the five relations
- See Also:
-
compose
public static <A,B, Multimap<A,C, D, E, F> F> compose(Supplier<Multimap> newInstance, Multimap<A, B> r, Multimap<B, C> s, Multimap<C, D> t, Multimap<D, E> u, Multimap<E, F> v) Returns a multimap which corresponds to the composition of five multimaps. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the domain of the first multimapB
- the range of the first multimap and the domain of the second multimapC
- the range of the second multimap and the domain of the third multimapD
- the range of the third multimap and the domain of the fourth multimapE
- the range of the fourth multimap and the domain of the fifth multimapF
- the range of the fifth multimap- Parameters:
newInstance
- a factory method (no parameters) to construct the resultr
- the first multimaps
- the second multimapt
- the third multimapu
- the fourth multimapv
- the fifth multimap- Returns:
- a multimap which corresponds to the composition of the five relations
- See Also:
-
compose
Returns a multimap which is a composition of arbitrary many multimaps, all of the same type. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the type of all contained elements- Parameters:
r
- the list of multimaps to compose- Returns:
- a multimap which corresponds to the composition of all given relations
- See Also:
-
compose
Returns a multimap which is a composition of arbitrary many multimaps, all of the same type. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the type of all contained elementsR
- the class of the result- Parameters:
newInstance
- a factory method (no parameters) to construct the resultr
- the list of multimaps to compose- Returns:
- a multimap which corresponds to the composition of all given relations
- See Also:
-
forward
Returns a multimap view on the entry set of a map. The result is backed by the argument. Changes to one of the collections are reflected by the outer. Adding to the multimap is not supported.The map must not contain null keys or values.
- Type Parameters:
A
- the domain of map and multimapB
- the range of map and multimap- Parameters:
map
- defines the contents of the multimap.- Returns:
- a multimap corresponding to the map
-
backward
Returns a multimap view on the entry set of a map, from its range to its domain. The result is backed by the argument. Changes to one of the collection is reflected by the outer.The map must not contain null keys or values.
- Type Parameters:
A
- the domain of map and range of multimapB
- the range of map and domain of multimap- Parameters:
map
- seen backwards from range to domain defines the contents of the multimap.- Returns:
- a multimap corresponding to the reverse map
-
support
Returns a set of all elements appearing on any side of the multimap. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the type of domain and range of the multimap- Parameters:
r
- the multimap the elements of which shall be returned- Returns:
- the set of all elements appearing on any side of the multimap.
-
reflexiveClosure
Modifies the argument to contain all identity pairs of all contained elements.- Type Parameters:
A
- domain and range type of the multimap- Parameters:
r
- multimap to modify- Returns:
- wether the argument has changed
-
reflexiveClosure
Modifies the argument to contain all identity pairs of elements given explicitly in the set argument.- Type Parameters:
A
- domain and range type of the multimap- Parameters:
r
- multimap to modifys
- all elements the identity pair of which shall be added- Returns:
- wether the argument has changed
-
reflexiveReduction
Modifies the argument to not contain an identity pair of any contained element.- Type Parameters:
A
- domain and range type of the multimap- Parameters:
r
- multimap to modify- Returns:
- wether the argument has changed
-
reflexiveReduction
Modifies the argument to not contain an identity pair of the explicitly given elements.- Type Parameters:
A
- domain and range type of the multimap- Parameters:
r
- multimap to modifys
- all elements the identity pair of which shall be removed- Returns:
- wether the argument has changed
-
symmetricClosure
Modifies the argument by adding to each pair also the inverse.- Type Parameters:
A
- domain and range type of the multimap- Parameters:
r
- multimap to modify- Returns:
- wether the argument has changed
-
toSymmetricClosure
Returns a new multimap which contains the given argument and its inversion. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- domain and range type of the multimap- Parameters:
r
- multimap to copy and modify- Returns:
- a new multimap. This is modifiable.
-
transitiveClosure
Modifies the argument by adding each pair which can be constructed by composing two or more pairs.- Type Parameters:
A
- domain and range type of the multimap- Parameters:
r
- multimap to modify- Returns:
- wether the argument has changed
- See Also:
-
transitiveClosureSparse
Modifies the argument by adding each pair which can be constructed by composing two or more pairs. Delivers the same result astransitiveClosure(Multimap)
, but is more efficient for large and sparse arguments.- Type Parameters:
A
- domain and range type of the multimap- Parameters:
r
- multimap to modify- Returns:
- wether the argument has changed
- See Also:
-
toTransitiveClosure
Returns a new multimap which contains the transitive closure of the argument. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- domain and range type of the multimap- Parameters:
r
- multimap to modify- Returns:
- a new mulitmap containing the transitive closure of the argument.
- See Also:
-
toTransitiveClosure
public static <A,R extends Multimap<A, R toTransitiveClosureA>> (Supplier<? extends R> newInstance, Multimap<A, A> r) Returns a new multimap which contains the transitive closure of the argument. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- domain and range type of the multimapR
- type of the result- Parameters:
newInstance
- a factory method (no parameters) to construct the resultr
- multimap to modify- Returns:
- a new mulitmap containing the transitive closure of the argument.
- See Also:
-
slice
public static <A,B, R sliceR extends Multimap<A, B>> (Supplier<R> newInstance, BiPredicate<? super A, ? super B> r, Set<? extends A> dom, Set<? extends B> ran) Returns a new multimap which contains all pairs from the given sets which fulfill the given predicate. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the domain type of the multimapB
- the range type of the multimapR
- type of the result- Parameters:
newInstance
- a factory method (no parameters) to construct the resultr
- the predicate to fulfilldom
- the domain elements to testran
- the range elements to test- Returns:
- a multimap which contains all pairs from the given sets which fulfill the given predicate.
-
slice
public static <A,B> Multimap<A,B> slice(BiPredicate<? super A, ? super B> r, Set<? extends A> dom, Set<? extends B> ran) Returns a new multimap which contains all pairs from the given sets which fulfill the given predicate. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the domain type of the multimapB
- the range type of the multimap- Parameters:
r
- the predicate to fulfilldom
- the domain elements to testran
- the range elements to test- Returns:
- a multimap which contains all pairs from the given sets which fulfill the given predicate.
-
toSum
public static <A,B> Multimap<A,B> toSum(Collection<? extends A> dom, Function<? super A, ? extends Collection<? extends B>> fun) Collect all combinations which result from applying the given set-valued function to all elements of the given collection. This istoSum(M, f) = ⋃ { m ∊ M ⚫ {m} × f(m) }
. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the domain type of the multimapB
- the range type of the multimap- Parameters:
dom
- the elements to which the function is appliedfun
- the function to apply- Returns:
- the resulting multimap
-
toSum
public static <A,B, R toSumR extends Multimap<A, B>> (Supplier<R> newInstance, Collection<? extends A> dom, Function<? super A, ? extends Collection<? extends B>> fun) Collect all combinations which result from applying the given set-valued function to all elements of the given collection. This istoSum(M, f) = ⋃ { m ∊ M ⚫ {m} × f(m) }
. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the domain type of the multimapB
- the range type of the multimapR
- type of the result- Parameters:
newInstance
- a factory method (no parameters) to construct the resultdom
- the elements to which the function is appliedfun
- the function to apply- Returns:
- the resulting multimap
-
unmodifiableMultimap
Returns a wrapper round the argument which does not allow modifications. The result is backed by the argument: Changes to the argument wil be reflected by the wrapper.- Type Parameters:
A
- the domain type of the multimapsB
- the range type of the multimasp- Parameters:
m
- the multimap to wrap- Returns:
- the wrapper which does not allow modifications
-
span
public static <A,B, Multimap<B,C> C> span(Function<? super A, ? extends B> left, Function<? super A, ? extends C> right, Collection<? extends A> gen) Returns a multimap the pairs of which combine the results of applying two functions to the elements of a given collection. It holds thatspan(f, g, A) = { x ∊ A ⚫ (f(x),g(x))}
. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the type of the original elements and the domain of both functionsB
- the range of the first function and of the domain of the resultC
- the type of the range of the first function and of the domain of the result- Parameters:
left
- the first function to applyright
- the second function to applygen
- the collection to which the functions shall be applied- Returns:
- the calculated multimap
-
span
public static <A,B, R spanC, R extends Multimap<B, C>> (Supplier<R> newInstance, Function<? super A, ? extends B> left, Function<? super A, ? extends C> right, Collection<? extends A> gen) Returns a multimap the pairs of which combine the results of applying two functions to the elements of a given collection. It holds thatspan(f, g, A) = { x ∊ A ⚫ (f(x),g(x))}
. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the type of the original elements and the domain of both functionsB
- the range of the first function and of the domain of the resultC
- the type of the range of the first function and of the domain of the resultR
- type of the result- Parameters:
newInstance
- a factory method (no parameters) to construct the resultleft
- the first function to applyright
- the second function to applygen
- the collection to which the functions shall be applied- Returns:
- the calculated multimap
-
toSpan
@Deprecated(forRemoval=true) public static <A,B, Multimap<B,C> C> toSpan(Function<? super A, ? extends B> left, Function<? super A, ? extends C> right, Collection<? extends A> gen) Deprecated, for removal: This API element is subject to removal in a future version.Returns a multimap the pairs of which combine the results of applying two functions to the elements of a given collection. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the type of the original elements and the domain of both functionsB
- the range of the first function and of the domain of the resultC
- the type of the range of the first function and of the domain of the result- Parameters:
left
- the first function to applyright
- the second function to applygen
- the collection to which the functions shall be applied- Returns:
- the calculated multimap
-
map
public static <A,B, Multimap<C,C, D> D> map(Function<? super A, ? extends C> left, Function<? super B, ? extends D> right, Multimap<? extends A, ? extends B> gen) Returns a new multimap the pairs of which combine the results of applying two functions to the two sides of the pairs in the given multimap. It holds thatspan(f, g, M) = { (a, b) ∊ M ⚫ (f(a),g(b))}
. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the type of the left side of the original elements and the domain of the first functionB
- the type of the right side of the original elements and the domain of the first functionC
- the type of the range of the first function and of the domain of the resultD
- the type of the range of the second function and of the range of the result- Parameters:
left
- the first function to applyright
- the second function to applygen
- the collection to which the functions shall be applied- Returns:
- the calculated multimap
-
map
public static <A,B, R mapC, D, R extends Multimap<C, D>> (Supplier<R> newInstance, Function<? super A, ? extends C> left, Function<? super B, ? extends D> right, Multimap<? extends A, ? extends B> gen) Returns a new multimap the pairs of which combine the results of applying two functions to the two sides of the pairs in the given multimap. It holds thatspan(f, g, M) = { (a, b) ∊ M ⚫ (f(a),g(b))}
. The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.- Type Parameters:
A
- the type of the left side of the original elements and the domain of the first functionB
- the type of the right side of the original elements and the domain of the first functionC
- the type of the range of the first function and of the domain of the resultD
- the type of the range of the second function and of the range of the resultR
- type of the multimaps- Parameters:
newInstance
- a factory method (no parameters) to construct the resultleft
- the first function to applyright
- the second function to applygen
- the collection to which the functions shall be applied- Returns:
- the calculated multimap
-
asMultimap
Returns a multimap view of the given set of map entries. The multimap will be backed by the given set; changes to both collections will be mutually reflected.- Type Parameters:
A
- the domain type of set and map entries.B
- the range type of set and map entries.- Parameters:
things
- the collection defining the multimap- Returns:
- a multimap which contains the given pairs.
-
choose
Returns an unmodifiable map which assigns to every element of the domain some arbitrary element of its image. The result is immutable and backed by the argument. Changes to the argument are reflected by the result.- Type Parameters:
A
- the domain of the multimapB
- the range of the multimap- Parameters:
m
- the multimap to choose from- Returns:
- a map which assigns to every element of the domain some arbitrary element of its image.
-
maxMatching
Find a maximum bijective function which is contained in the given relation. This means: Deliver a maximum subset of the pairs of the given multimap such that every element of the domain appears at most once, and so of the range. Often this is called "solving a matching problem".The result is a fresh and independent instance; its values are calculated instantly; no future changes to the collection argument will be reflected.
- Type Parameters:
A
- the domain type of the multimapsB
- the range type of the multimaps- Parameters:
rel
- the relation to analyse- Returns:
- the found maximal bijection.
-
compose(Multimap,Multimap)
instead.