Class AbstractMultimap<A,B>

java.lang.Object
java.util.AbstractCollection<Map.Entry<A,B>>
eu.bandm.tools.util.multi.AbstractMultimap<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 abstract class AbstractMultimap<A,B> extends AbstractCollection<Map.Entry<A,B>> implements Multimap<A,B>
Top level of the generic implementations of Multimap. The next level will supply the particular storage room. Only the methods AbstractCollection.size() and AbstractCollection.iterator() are not implemented here.
  • Constructor Details

    • AbstractMultimap

      protected AbstractMultimap()
  • Method Details

    • add

      public boolean add(A a, B b)
      Adds a pair to this multimap if not already present.

      The default implementation calls #add(Object) with a newly created map entry to hold the pair. Subclasses may override this method for a more efficient implementation.

      Specified by:
      add in interface Multimap<A,B>
      Parameters:
      a - the left element of the pair
      b - the right element of the pair
      Returns:
      true if this multimap has changed, false if it has not because it already contained the pair
      See Also:
    • remove

      public boolean remove(A a, B b)
      Description copied from interface: Multimap
      Removes a pair from 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.
    • 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.
    • domain

      public Set<A> domain()
      Description copied from interface: Multimap
      Returns the set of left components of pairs in this multimap.

      The returned set is backed by this multimap, such that changes to this multimap are reflected by the set. The behavior of modifications of this multimap concurrent to iteration of the set is unspecified.

      If this multimap supports the removeDomain operation, then the returned set and its iterators must support the remove operation, and changes by these operations must be reflected by this multimap.

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

      public Set<B> range()
      Description copied from interface: Multimap
      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.

      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)
      Description copied from interface: Multimap
      Convenience method for untyped inquiry.
      Specified by:
      imageUnchecked 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)
      Description copied from interface: Multimap
      Convenience method for untyped inquiry.
      Specified by:
      preimageUnchecked in interface Multimap<A,B>
      See Also:
    • 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>