Class Multimaps

java.lang.Object
eu.bandm.tools.util.multi.Multimaps

public final class Multimaps extends Object
Utility class of constants and combinators for Multimap.
  • Method Details

    • cache

      public static <A> Comparator<A> cache(Comparator<? super A> c)
      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

      public static <A, B> Map<A,B> intoMap(Multimap<A,B> in, Map<A,B> out)
      Adds the pairs from a Multimap into a Map, if possible.
      Type Parameters:
      A - the domain of map and multimap
      B - the range of map and multimap
      Parameters:
      in - MultiMap to copy to the map
      out - 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

      public static <A, B> Multimap<A,B> empty()
      Returns an unmodifiable multimap which is empty.
      Type Parameters:
      A - the domain type of the multimap
      B - the range type of the multimap
      Returns:
      an unmodifiable multimap which is empty.
    • singleton

      public static <A, B> Multimap<A,B> singleton(A a, B b)
      Returns an unmodifiable multimap which contains only the given pair.
      Type Parameters:
      A - the domain type of the multimap
      B - the range type of the multimap
      Parameters:
      a - the domain element of the contained pair
      b - the range element of the contained pair
      Returns:
      an unmodifiable multimap which contains only the given pair
    • id

      public static <A> Multimap<A,A> id(Set<A> support)
      Returns a modifiable multimap which realizes the id1entity relation of all elements from the given set. This is based on Object.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

      public static <A, B> Multimap<A,B> all(A dom, Set<B> ran)
      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 multimap
      B - the range type of the multimap
      Parameters:
      dom - the domain of the multimap
      ran - the range of the multimap
      Returns:
      the multimap of all combinations.
    • all

      public static <A, B> Multimap<A,B> all(Set<A> dom, B ran)
      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 multimap
      B - the range type of the multimap
      Parameters:
      dom - the domain of the multimap
      ran - the range of the multimap
      Returns:
      the multimap of all combinations.
    • all

      public static <A, B> Multimap<A,B> all(Set<A> dom, Set<B> ran)
      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 multimap
      B - the range type of the multimap
      Parameters:
      dom - the domain of the multimap
      ran - the range of the multimap
      Returns:
      the multimap of all combinations.
    • inverse

      @Deprecated(forRemoval=true) public static <A, B> Multimap<B,A> inverse(Multimap<A,B> r)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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 result
      B - 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

      public static <A, B> Multimap<B,A> converse(Multimap<A,B> r)
      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 result
      B - 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, C> Multimap<A,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.
      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 result
      B - the range type of the first multimap and of the domain of the second
      C - the range type of the second multimap and of the result
      Parameters:
      r - the first multimap to compose
      s - the second multimap to compose
      result - where to add the calculted pairs
      Returns:
      the multimap given as result
    • compose

      public static <A, B, C, R extends Multimap<? super A, ? super C>> R compose(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 result
      B - the range type of the first multimap and of the domain of the second
      C - the range type of the second multimap and of the result
      R - the class of the result
      Parameters:
      newInstance - a factory method (no parameters) to construct the result
      r - the first multimap to compose
      s - the second multimap to compose
      Returns:
      the new multimap representing the relation composition
    • compose

      public static <A, B, C> HashMultimap<A,C> compose(Multimap<A,B> r, Multimap<B,C> s)
      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 result
      B - the range type of the first multimap and of the domain of the second
      C - the range type of the second multimap and of the result
      Parameters:
      r - the first multimap to compose
      s - the second multimap to compose
      Returns:
      the new multimap representing the relation composition
    • compose

      public static <A, B, C, D> Multimap<A,D> compose(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 multimap
      B - the range of the first multimap and the domain of the second multimap
      C - the range of the second multimap and the domain of the third multimap
      D - the range of the third multimap
      Parameters:
      r - the first multimap
      s - the second multimap
      t - the third multimap
      Returns:
      a multimap which corresponds to the composition of the three relations
      See Also:
    • compose

      public static <A, B, C, D> Multimap<A,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 multimap
      B - the range of the first multimap and the domain of the second multimap
      C - the range of the second multimap and the domain of the third multimap
      D - the range of the third multimap
      Parameters:
      newInstance - a factory method (no parameters) to construct the result
      r - the first multimap
      s - the second multimap
      t - the third multimap
      Returns:
      a multimap which corresponds to the composition of the three relations
      See Also:
    • compose

      public static <A, B, C, D, E> Multimap<A,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 multimap
      B - the range of the first multimap and the domain of the second multimap
      C - the range of the second multimap and the domain of the third multimap
      D - the range of the third multimap and the domain of the fourth multimap
      E - the range of the fourth multimap
      Parameters:
      r - the first multimap
      s - the second multimap
      t - the third multimap
      u - the fourth multimap
      Returns:
      a multimap which corresponds to the composition of the four relations
      See Also:
    • compose

      public 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. 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 multimap
      B - the range of the first multimap and the domain of the second multimap
      C - the range of the second multimap and the domain of the third multimap
      D - the range of the third multimap and the domain of the fourth multimap
      E - the range of the fourth multimap
      Parameters:
      newInstance - a factory method (no parameters) to construct the result
      r - the first multimap
      s - the second multimap
      t - the third multimap
      u - the fourth multimap
      Returns:
      a multimap which corresponds to the composition of the four relations
      See Also:
    • compose

      public static <A, B, C, D, E, F> Multimap<A,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 multimap
      B - the range of the first multimap and the domain of the second multimap
      C - the range of the second multimap and the domain of the third multimap
      D - the range of the third multimap and the domain of the fourth multimap
      E - the range of the fourth multimap and the domain of the fifth multimap
      F - the range of the fifth multimap
      Parameters:
      r - the first multimap
      s - the second multimap
      t - the third multimap
      u - the fourth multimap
      v - the fifth multimap
      Returns:
      a multimap which corresponds to the composition of the five relations
      See Also:
    • compose

      public 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. 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 multimap
      B - the range of the first multimap and the domain of the second multimap
      C - the range of the second multimap and the domain of the third multimap
      D - the range of the third multimap and the domain of the fourth multimap
      E - the range of the fourth multimap and the domain of the fifth multimap
      F - the range of the fifth multimap
      Parameters:
      newInstance - a factory method (no parameters) to construct the result
      r - the first multimap
      s - the second multimap
      t - the third multimap
      u - the fourth multimap
      v - the fifth multimap
      Returns:
      a multimap which corresponds to the composition of the five relations
      See Also:
    • compose

      public static <A> Multimap<A,A> compose(Multimap<A,A>... r)
      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

      public static <A, R extends Multimap<A, A>> R compose(Supplier<? extends R> newInstance, R... r)
      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
      R - the class of the result
      Parameters:
      newInstance - a factory method (no parameters) to construct the result
      r - the list of multimaps to compose
      Returns:
      a multimap which corresponds to the composition of all given relations
      See Also:
    • forward

      public static <A, B> Multimap<A,B> forward(Map<A,B> map)
      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 multimap
      B - the range of map and multimap
      Parameters:
      map - defines the contents of the multimap.
      Returns:
      a multimap corresponding to the map
    • backward

      public static <A, B> Multimap<B,A> backward(Map<A,B> map)
      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 multimap
      B - 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

      public static <A> Set<A> support(Multimap<A,A> r)
      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

      public static <A> boolean reflexiveClosure(Multimap<A,A> r)
      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

      public 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.
      Type Parameters:
      A - domain and range type of the multimap
      Parameters:
      r - multimap to modify
      s - all elements the identity pair of which shall be added
      Returns:
      wether the argument has changed
    • reflexiveReduction

      public static <A> boolean reflexiveReduction(Multimap<A,A> r)
      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

      public 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.
      Type Parameters:
      A - domain and range type of the multimap
      Parameters:
      r - multimap to modify
      s - all elements the identity pair of which shall be removed
      Returns:
      wether the argument has changed
    • symmetricClosure

      public static <A> boolean symmetricClosure(Multimap<A,A> r)
      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

      public static <A> Multimap<A,A> toSymmetricClosure(Multimap<A,A> r)
      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

      public 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.
      Type Parameters:
      A - domain and range type of the multimap
      Parameters:
      r - multimap to modify
      Returns:
      wether the argument has changed
      See Also:
    • transitiveClosureSparse

      public 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. Delivers the same result as transitiveClosure(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

      public static <A> Multimap<A,A> toTransitiveClosure(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 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, A>> R toTransitiveClosure(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 multimap
      R - type of the result
      Parameters:
      newInstance - a factory method (no parameters) to construct the result
      r - multimap to modify
      Returns:
      a new mulitmap containing the transitive closure of the argument.
      See Also:
    • slice

      public static <A, B, R extends Multimap<A, B>> R slice(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 multimap
      B - the range type of the multimap
      R - type of the result
      Parameters:
      newInstance - a factory method (no parameters) to construct the result
      r - the predicate to fulfill
      dom - the domain elements to test
      ran - 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 multimap
      B - the range type of the multimap
      Parameters:
      r - the predicate to fulfill
      dom - the domain elements to test
      ran - 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 is toSum(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 multimap
      B - the range type of the multimap
      Parameters:
      dom - the elements to which the function is applied
      fun - the function to apply
      Returns:
      the resulting multimap
    • toSum

      public static <A, B, R extends Multimap<A, B>> R toSum(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 is toSum(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 multimap
      B - the range type of the multimap
      R - type of the result
      Parameters:
      newInstance - a factory method (no parameters) to construct the result
      dom - the elements to which the function is applied
      fun - the function to apply
      Returns:
      the resulting multimap
    • unmodifiableMultimap

      public static <A, B> Multimap<A,B> unmodifiableMultimap(Multimap<? extends A,? extends B> m)
      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 multimaps
      B - 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, 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. It holds that span(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 functions
      B - the range of the first function and of the domain of the result
      C - the type of the range of the first function and of the domain of the result
      Parameters:
      left - the first function to apply
      right - the second function to apply
      gen - the collection to which the functions shall be applied
      Returns:
      the calculated multimap
    • span

      public static <A, B, C, R extends Multimap<B, C>> R span(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 that span(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 functions
      B - the range of the first function and of the domain of the result
      C - the type of the range of the first function and of the domain of the result
      R - type of the result
      Parameters:
      newInstance - a factory method (no parameters) to construct the result
      left - the first function to apply
      right - the second function to apply
      gen - the collection to which the functions shall be applied
      Returns:
      the calculated multimap
    • toSpan

      @Deprecated(forRemoval=true) public 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.
      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 functions
      B - the range of the first function and of the domain of the result
      C - the type of the range of the first function and of the domain of the result
      Parameters:
      left - the first function to apply
      right - the second function to apply
      gen - the collection to which the functions shall be applied
      Returns:
      the calculated multimap
    • map

      public 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. It holds that span(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 function
      B - the type of the right side of the original elements and the domain of the first function
      C - the type of the range of the first function and of the domain of the result
      D - the type of the range of the second function and of the range of the result
      Parameters:
      left - the first function to apply
      right - the second function to apply
      gen - the collection to which the functions shall be applied
      Returns:
      the calculated multimap
    • map

      public static <A, B, C, D, R extends Multimap<C, D>> R map(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 that span(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 function
      B - the type of the right side of the original elements and the domain of the first function
      C - the type of the range of the first function and of the domain of the result
      D - the type of the range of the second function and of the range of the result
      R - type of the multimaps
      Parameters:
      newInstance - a factory method (no parameters) to construct the result
      left - the first function to apply
      right - the second function to apply
      gen - the collection to which the functions shall be applied
      Returns:
      the calculated multimap
    • asMultimap

      public static <A, B> Multimap<A,B> asMultimap(Set<Map.Entry<A,B>> things)
      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

      public static <A, B> Map<A,B> choose(Multimap<A,B> m)
      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 multimap
      B - 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

      public static <A, B> Multimap<A,B> maxMatching(Multimap<A,B> rel)
      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 multimaps
      B - the range type of the multimaps
      Parameters:
      rel - the relation to analyse
      Returns:
      the found maximal bijection.