Class UnmodifiableMultimap<A,B>

java.lang.Object
java.util.AbstractCollection<Map.Entry<A,B>>
eu.bandm.tools.util.multi.UnmodifiableMultimap<A,B>
Type Parameters:
A - type of the domain elements
B - type of the range elements
All Implemented Interfaces:
Multimap<A,B>, Iterable<Map.Entry<A,B>>, Collection<Map.Entry<A,B>>, BiPredicate<A,B>, Set<Map.Entry<A,B>>

abstract class UnmodifiableMultimap<A,B> extends AbstractCollection<Map.Entry<A,B>> implements Multimap<A,B>
A wrapper to protect the contents of an instance of a multimap. Not to be called by the user, but by the factory methods in Multimaps. To create such a wrapper, use Multimaps.unmodifiableMultimap(eu.bandm.tools.util.multi.Multimap<? extends A, ? extends B>). All methods which try to change the state of this instance throw an UnsupportedOperationException.
  • Constructor Details

    • UnmodifiableMultimap

      public UnmodifiableMultimap()
      Only constructor
  • Method Details

    • add

      public boolean add(A a, B b)
      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:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
    • contains

      public final 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.
      Returns:
      whether this multimap contains a pair with the given components.
    • remove

      public final boolean remove(A a, B b)
      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:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
    • removeUnchecked

      public final boolean removeUnchecked(Object a, Object b)
      Convenience method for untyped remove.
      Specified by:
      removeUnchecked 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:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
      See Also:
    • removeDomain

      public final boolean removeDomain(A a)
      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:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
    • removeDomainUnchecked

      public final boolean removeDomainUnchecked(Object a)
      Convenience method for untyped remove.
      Specified by:
      removeDomainUnchecked in interface Multimap<A,B>
      Parameters:
      a - the left component of all pairs to remove.
      Returns:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
      See Also:
    • removeRange

      public final boolean removeRange(B b)
      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:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
    • removeRangeUnchecked

      public final boolean removeRangeUnchecked(Object b)
      Convenience method for untyped remove. Removes all pairs with a given right component from this multimap.
      Specified by:
      removeRangeUnchecked in interface Multimap<A,B>
      Parameters:
      b - the right component of all pairs to remove.
      Returns:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
      See Also:
    • removeAllDomain

      public final boolean removeAllDomain(Collection<? extends A> a)
      Removes all pairs with a left component in the given collection from this multimap.
      Specified by:
      removeAllDomain in interface Multimap<A,B>
      Parameters:
      a - the set of left component of all pairs to remove.
      Returns:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
    • removeAllDomainUnchecked

      public final boolean removeAllDomainUnchecked(Collection<?> a)
      Convenience method for untyped remove.
      Specified by:
      removeAllDomainUnchecked in interface Multimap<A,B>
      Parameters:
      a - the set of left component of all pairs to remove.
      Returns:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
      See Also:
    • retainAllDomain

      public final boolean retainAllDomain(Collection<? extends A> a)
      Removes from this multimap all pairs with a left component which is not in the given collection.
      Specified by:
      retainAllDomain in interface Multimap<A,B>
      Parameters:
      a - the set of left component of all pairs not to remove.
      Returns:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
    • retainAllDomainUnchecked

      public final boolean retainAllDomainUnchecked(Collection<?> a)
      Convenience method for untyped remove.
      Specified by:
      retainAllDomainUnchecked in interface Multimap<A,B>
      Parameters:
      a - the set of left component of all pairs not to remove.
      Returns:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
      See Also:
    • removeAllRange

      public final boolean removeAllRange(Collection<? extends B> b)
      Removes all pairs with a right component in the given collection from this multimap.
      Specified by:
      removeAllRange in interface Multimap<A,B>
      Parameters:
      b - the set of the right component of all pairs to remove.
      Returns:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
    • removeAllRangeUnchecked

      public final boolean removeAllRangeUnchecked(Collection<?> b)
      Convenience method for untyped remove. Removes all pairs with a right component in the given collection from this multimap.
      Specified by:
      removeAllRangeUnchecked in interface Multimap<A,B>
      Parameters:
      b - the set of the right component of all pairs to remove.
      Returns:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
      See Also:
    • retainAllRange

      public final boolean retainAllRange(Collection<? extends B> b)
      Removes from this multimap all pairs with a right component which is not in the given collection.
      Specified by:
      retainAllRange in interface Multimap<A,B>
      Parameters:
      b - the set of the right component of all pairs not emove.
      Returns:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
    • retainAllRangeUnchecked

      public final boolean retainAllRangeUnchecked(Collection<?> b)
      Convenience method for untyped remove. Removes all pairs with a right component which is not the given collection from this multimap.
      Specified by:
      retainAllRangeUnchecked in interface Multimap<A,B>
      Parameters:
      b - the set of the right component of all pairs not emove.
      Returns:
      whether this multimap has been changed by this operation
      Throws:
      UnsupportedOperationException - always
      See Also:
    • 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.
    • 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. The result is backed by the argument. Subsequent changes to either Collection are reflected by the other.
      Specified by:
      imageMap in interface Multimap<A,B>
      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.
    • 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.
    • 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. The result is backed by the argument. Subsequent changes to either Collection are reflected by the other.
      Specified by:
      preimageMap in interface Multimap<A,B>
      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.