Class ForwardMultimap<A,B>

java.lang.Object
java.util.AbstractCollection<Map.Entry<A,B>>
eu.bandm.tools.ops.ForwardMultimap<A,B>
All Implemented Interfaces:
Multimap<A,B>, Iterable<Map.Entry<A,B>>, Collection<Map.Entry<A,B>>, BiPredicate<A,B>, Set<Map.Entry<A,B>>

public class ForwardMultimap<A,B> extends AbstractCollection<Map.Entry<A,B>> implements Multimap<A,B>
Implementation which allows only one domain element per range elment, equivalent to a simple map.
  • Field Details

    • forward

      protected final Map<A,B> forward
  • Constructor Details

    • ForwardMultimap

      public ForwardMultimap(Map<A,B> forward)
    • ForwardMultimap

      public ForwardMultimap(Collection<? extends Map.Entry<A,B>> c)
  • Method Details

    • test

      public boolean test(A a, B b)
      Specified by:
      test in interface BiPredicate<A,B>
    • size

      public int size()
      Specified by:
      size in interface Collection<A>
      Specified by:
      size in interface Set<A>
      Specified by:
      size in class AbstractCollection<Map.Entry<A,B>>
    • iterator

      public Iterator<Map.Entry<A,B>> iterator()
      Specified by:
      iterator in interface Collection<A>
      Specified by:
      iterator in interface Iterable<A>
      Specified by:
      iterator in interface Set<A>
      Specified by:
      iterator in class AbstractCollection<Map.Entry<A,B>>
    • add

      public boolean add(Map.Entry<A,B> e)
      Specified by:
      add in interface Collection<A>
      Specified by:
      add in interface Set<A>
      Overrides:
      add in class AbstractCollection<Map.Entry<A,B>>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<A>
      Specified by:
      clear in interface Set<A>
      Overrides:
      clear in class AbstractCollection<Map.Entry<A,B>>
    • add

      public boolean add(A a, B b)
      Description copied from interface: Multimap
      Adds a pair to this multimap. This operation must be stable: adding a pair that equals any pair contained in this multimap componentwise must not change this multimap.
      Specified by:
      add in interface Multimap<A,B>
      Parameters:
      a - the left component of the pair to add.
      b - the right component of the pair to add.
      Returns:
      true if this multimap has been changed by this operation, false otherwise.
    • contains

      public boolean contains(A a, B b)
      Description copied from interface: Multimap
      Whether this multimap contains a pair with the given components.
      Specified by:
      contains in interface Multimap<A,B>
      Parameters:
      a - the left component of the pair to add.
      b - the right component of the pair to add.
    • containsUnchecked

      public boolean containsUnchecked(Object a, Object b)
      Specified by:
      containsUnchecked in interface Multimap<A,B>
    • remove

      public boolean remove(A a, B b)
      Description copied from interface: Multimap
      Removes a pair from this this multimap. Removing a pair that equals no pair contained in this multimap componentwise must not change this multimap.
      Specified by:
      remove in interface Multimap<A,B>
      Parameters:
      a - the left component of the pair to remove.
      b - the right component of the pair to remove.
      Returns:
      true if this multimap has been changed by this operation, false otherwise.
    • removeUnchecked

      public boolean removeUnchecked(Object a, Object b)
      Specified by:
      removeUnchecked in interface Multimap<A,B>
    • removeDomain

      public boolean removeDomain(A a)
      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 interface Multimap<A,B>
      Parameters:
      a - the left component of all pairs to remove.
      Returns:
      true if this multimap has been changed by this operation, false otherwise.
    • removeDomainUnchecked

      public boolean removeDomainUnchecked(Object a)
    • removeRange

      public boolean removeRange(B b)
      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 interface Multimap<A,B>
      Parameters:
      b - the right component of all pairs to remove.
      Returns:
      true if this multimap has been changed by this operation, false otherwise.
    • removeRangeUnchecked

      public boolean removeRangeUnchecked(Object b)
    • removeAllDomain

      public boolean removeAllDomain(Collection<? extends A> c)
      Description copied from interface: Multimap
      Removes all pairs with a left component in the given collection from this multimap.
      Specified by:
      removeAllDomain in interface Multimap<A,B>
    • removeAllDomainUnchecked

      public boolean removeAllDomainUnchecked(Collection<?> c)
      Specified by:
      removeAllDomainUnchecked in interface Multimap<A,B>
      See Also:
    • retainAllDomain

      public boolean retainAllDomain(Collection<? extends A> c)
      Description copied from interface: Multimap
      Removes all pairs with a left component which is not the given collection from this multimap.
      Specified by:
      retainAllDomain in interface Multimap<A,B>
    • retainAllDomainUnchecked

      public boolean retainAllDomainUnchecked(Collection<?> c)
      Specified by:
      retainAllDomainUnchecked in interface Multimap<A,B>
      See Also:
    • removeAllRange

      public boolean removeAllRange(Collection<? extends B> c)
      Description copied from interface: Multimap
      Removes all pairs with a right component in the given collection from this multimap.
      Specified by:
      removeAllRange in interface Multimap<A,B>
    • removeAllRangeUnchecked

      public boolean removeAllRangeUnchecked(Collection<?> c)
      Specified by:
      removeAllRangeUnchecked in interface Multimap<A,B>
      See Also:
    • retainAllRange

      public boolean retainAllRange(Collection<? extends B> c)
      Description copied from interface: Multimap
      Removes all pairs with a right component which is not the given collection from this multimap.
      Specified by:
      retainAllRange in interface Multimap<A,B>
    • retainAllRangeUnchecked

      public boolean retainAllRangeUnchecked(Collection<?> c)
      Specified by:
      retainAllRangeUnchecked in interface Multimap<A,B>
      See Also:
    • domain

      public Set<A> 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 removeDomain operation, then the returned set and its iterators must support the remove operation, and changes by these operations must be reflected by this multimap.

      The set returned by this implementation and its iterator supports the remove method if the entrySet of the underlying map does.

      Specified by:
      domain in interface Multimap<A,B>
      Returns:
      the set of left components of pairs in this multimap.
    • range

      public Set<B> range()
      Returns the set of right components of pairs in this multimap.

      If this multimap supports the removeRange operation, then the returned set and its iterators must support the remove operation.

      The set returned by this implementation and its iterator supports the remove method if the entrySet of the underlying map does.

      Specified by:
      range in interface Multimap<A,B>
      Returns:
      the set of right components of pairs in this multimap.
    • image

      public Set<B> image(A a)
      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.

      Specified by:
      image in interface Multimap<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.
    • imageUnchecked

      public Set<B> imageUnchecked(Object a)
      Specified by:
      imageUnchecked in interface Multimap<A,B>
      See Also:
    • imageAll

      public Set<B> imageAll(Collection<? extends A> c)
      Description copied from interface: Multimap
      Returns the set of right components of pairs in this multimap, which have a left component in the given set.
      Specified by:
      imageAll in interface Multimap<A,B>
    • imageAllUnchecked

      public Set<B> imageAllUnchecked(Collection<?> c)
      Specified by:
      imageAllUnchecked in interface Multimap<A,B>
      See Also:
    • imageMap

      public Map<A,Set<B>> 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.
      Specified by:
      imageMap in interface Multimap<A,B>
    • preimage

      public Set<A> preimage(B b)
      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.

      Specified by:
      preimage in interface Multimap<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.
    • preimageUnchecked

      public Set<A> preimageUnchecked(Object b)
      Specified by:
      preimageUnchecked in interface Multimap<A,B>
      See Also:
    • preimageAll

      public Set<A> preimageAll(Collection<? extends B> c)
      Description copied from interface: Multimap
      Returns the set of left components of pairs in this multimap, which have a right component in the given set.
      Specified by:
      preimageAll in interface Multimap<A,B>
    • preimageAllUnchecked

      public Set<A> preimageAllUnchecked(Collection<?> c)
      Specified by:
      preimageAllUnchecked in interface Multimap<A,B>
    • preimageMap

      public Map<B,Set<A>> 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.
      Specified by:
      preimageMap in interface Multimap<A,B>