Class IndexMultimap<A,B>

All Implemented Interfaces:
Nullfree, Multimap<A,B>, Iterable<Map.Entry<A,B>>, Collection<Map.Entry<A,B>>, BiPredicate<A,B>, Set<Map.Entry<A,B>>

public class IndexMultimap<A,B> extends AbstractMultimap<A,B>
Optimized Implementation using bit sets for both directions.
  • Constructor Details

    • IndexMultimap

      public IndexMultimap(IndexMultimap<A,B> m)
    • IndexMultimap

      public IndexMultimap(Index<A> domIndex, Index<B> ranIndex)
  • Method Details

    • getDomainIndex

      public Index<A> getDomainIndex()
    • getRangeIndex

      public Index<B> getRangeIndex()
    • add

      public boolean add(int i, int j)
      Special for indexed bases multimaps, is NOT an override.
    • remove

      public boolean remove(int i, int j)
      Special for indexed bases multimaps, is NOT an override.
    • contains

      public boolean contains(int i, int j)
      Special for indexed bases multimaps, is NOT an override.
    • 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>>
    • 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>
      Overrides:
      contains in class AbstractMultimap<A,B>
      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.
    • containsUnchecked

      public boolean containsUnchecked(Object a, Object b)
      Description copied from interface: Multimap
      Convenience method for untyped inquiry.
      Parameters:
      a - the left component of the pair to test
      b - the right component of the pair to test
      Returns:
      whether this multimap contains a pair with the given components.
      See Also:
    • contains

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

      public boolean add(A a, B b)
      Description copied from class: AbstractMultimap
      Adds a pair to this multimap if not already present.

      The default implementation calls AbstractCollection.add(E) 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>
      Overrides:
      add in class AbstractMultimap<A,B>
      Parameters:
      a - the left element of the pair
      b - the right element of the pair
      Returns:
      true if this multimap has changed. Otherwise false, because it already contained the pair
      See Also:
    • 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>>
    • 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>
      Overrides:
      remove in class AbstractMultimap<A,B>
      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
    • removeUnchecked

      public boolean removeUnchecked(Object a, Object b)
      Description copied from interface: Multimap
      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:
    • 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>
      Overrides:
      domain in class AbstractMultimap<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.

      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 removeRange 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:
      range in interface Multimap<A,B>
      Overrides:
      range in class AbstractMultimap<A,B>
      Returns:
      the set of right components of pairs in this multimap.
    • 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) ;
       }
       
      Parameters:
      a - the left component of all pairs to remove.
      Returns:
      whether this multimap has been changed by this operation
    • image

      public IndexSet<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>
      Overrides:
      image in class AbstractMultimap<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 IndexSet<B> imageUnchecked(Object a)
      Description copied from interface: Multimap
      Convenience method for untyped inquiry.
      Specified by:
      imageUnchecked in interface Multimap<A,B>
      Overrides:
      imageUnchecked in class AbstractMultimap<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.
      See Also:
    • imageAll

      public IndexSet<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.
      Parameters:
      c - a set of left components.
      Returns:
      the set of right components of pairs with a left component in the given set.
    • imageAllUnchecked

      public IndexSet<B> imageAllUnchecked(Collection<?> c)
      Description copied from interface: Multimap
      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:
    • preimage

      public IndexSet<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>
      Overrides:
      preimage in class AbstractMultimap<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.