Interface Multiset<A>

Type Parameters:
A - type of the contained elements
All Superinterfaces:
Iterable<A>, Serializable
All Known Subinterfaces:
SortedMultiset<A>
All Known Implementing Classes:
AbstractMultiset, HashMultiset, TreeMultiset, UnmodifiableMultiset

public interface Multiset<A> extends Iterable<A>, Serializable
Structure similar to a set, but every element can be contained more than once. Therefore an iterator can deliver the same element multiple times, as often that element is contained. Corresponds to a map from the domain type into natural numbers (including 0).
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(A a)
    Add one element once to this set.
    boolean
    add(A a, int i)
    Add one element multiple times to this set.
    default boolean
    addAll(Multiset<? extends A> other)
    Add all elements contained in the argument to this multiset.
    void
    Remove all objects from this instance.
    boolean
    Returns whether a particular element is contained at least once in this set.
    boolean
    Returns whether a particular element is contained at least once in this set.
    int
    count(A a)
    Returns how many times the given element is contained in this set.
    int
    countAll(Collection<? extends A> a)
    Sum up how many times the elements in the given collection are contained in this set.
    int
    Sum up how many times the elements in the given collection are contained in this set.
    int
    Returns how many times the given element is contained in this set.
    Returns the set of all elements contained at least once in this set.
    boolean
    Returns whether this set is empty.
    boolean
    remove(A a)
    Remove the given element once from this set.
    boolean
    removeAll(Collection<? extends A> c)
    Remove all elements in the given collection completely from this set.
    boolean
    Remove all elements in the given collection completely from this set.
    boolean
    Remove the given element completely from this set.
    boolean
    Remove the given element completely from this set.
    boolean
    Remove the given element once from this set.
    boolean
    retainAll(Collection<? extends A> c)
    Remove all elements not contained in the given collection completely from this set.
    boolean
    Remove all elements not contained in the given collection completely from this set.
    Returns a map which assigns each element contained at least once in this set to how often it is contained.

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator
  • Method Details

    • isEmpty

      boolean isEmpty()
      Returns whether this set is empty.
      Returns:
      whether this set is empty.
    • clear

      void clear()
      Remove all objects from this instance.
    • add

      boolean add(A a)
      Add one element once to this set. This means to increase the number of contained elements by one.
      Parameters:
      a - element to add.
      Returns:
      whether the Multiset has been changed. Is defined only for a better analogy to the philosophy of java.util.Collection, but indeed returns always true.
    • addAll

      default boolean addAll(Multiset<? extends A> other)
      Add all elements contained in the argument to this multiset.
      Parameters:
      other - the other mulitset to add
      Returns:
      whether the Multiset has been changed. This is the case when the argumentis not empty.
    • add

      boolean add(A a, int i)
      Add one element multiple times to this set. This means to increase the number of contained elements by the given mulitplicity.
      Parameters:
      a - element to add.
      i - number of additions. Must be greater or equal to zero.
      Returns:
      whether the Multiset has been changed. This is the case when i is greater zero.
      Throws:
      IllegalArgumentException - if i is less than zero.
    • contains

      boolean contains(A a)
      Returns whether a particular element is contained at least once in this set.
      Parameters:
      a - element to test.
      Returns:
      whether a the given element is contained at least once in this set.
    • containsUnchecked

      boolean containsUnchecked(Object a)
      Returns whether a particular element is contained at least once in this set.
      Parameters:
      a - element to test.
      Returns:
      whether a the given element is contained at least once in this set.
    • remove

      boolean remove(A a)
      Remove the given element once from this set. That means, decrement the number of its containments if and only if it is greater than zero.
      Parameters:
      a - element to remove.
      Returns:
      whether this instance has changed.
    • removeUnchecked

      boolean removeUnchecked(Object a)
      Remove the given element once from this set. That means, decrement the number of its containments iff it is greater zero.
      Parameters:
      a - element to remove.
      Returns:
      whether this instance has changed.
    • removeDomain

      boolean removeDomain(A a)
      Remove the given element completely from this set.
      Parameters:
      a - element to remove.
      Returns:
      whether this instance has changed.
    • removeDomainUnchecked

      boolean removeDomainUnchecked(Object a)
      Remove the given element completely from this set.
      Parameters:
      a - element to remove.
      Returns:
      whether this instance has changed.
    • removeAll

      boolean removeAll(Collection<? extends A> c)
      Remove all elements in the given collection completely from this set.
      Parameters:
      c - collection of all elements to remove
      Returns:
      whether this instance has changed
    • removeAllUnchecked

      boolean removeAllUnchecked(Collection<?> c)
      Remove all elements in the given collection completely from this set.
      Parameters:
      c - collection of all elements to remove
      Returns:
      whether this instance has changed
    • retainAll

      boolean retainAll(Collection<? extends A> c)
      Remove all elements not contained in the given collection completely from this set.
      Parameters:
      c - collection of all elements not to remove
      Returns:
      whether this instance has changed
    • retainAllUnchecked

      boolean retainAllUnchecked(Collection<?> c)
      Remove all elements not contained in the given collection completely from this set.
      Parameters:
      c - collection of all elements not to remove
      Returns:
      whether this instance has changed
    • domain

      Set<A> domain()
      Returns the set of all elements contained at least once in this set. It holds that domain().equals(supportMap().keySet()). The result is backed by the argument. Changes to one collection are reflected by the other. When visiting this view, the ordering corresponds to that of the multiset.
      Returns:
      the set of all elements contained at least once in this instance.
    • supportMap

      Map<A,Integer> supportMap()
      Returns a map which assigns each element contained at least once in this set to how often it is contained. It holds that no zero is contained in the range of this map. The result is backed by the argument. Changes to one collection are reflected by the other. When visiting this view, the ordering corresponds to that of the multiset.
      Returns:
      a map which assigns each element contained at least once in this instance to how often it is contained.
    • count

      int count(A a)
      Returns how many times the given element is contained in this set.
      Parameters:
      a - the element to test.
      Returns:
      how many times the given element is contained in this set.
    • countUnchecked

      int countUnchecked(Object a)
      Returns how many times the given element is contained in this set.
      Parameters:
      a - the element to test.
      Returns:
      how many times the given element is contained in this set.
    • countAll

      int countAll(Collection<? extends A> a)
      Sum up how many times the elements in the given collection are contained in this set.
      Parameters:
      a - the collection of elements to count.
      Returns:
      how many times the elements in the given collection are contained in this set.
    • countAllUnchecked

      int countAllUnchecked(Collection<?> a)
      Sum up how many times the elements in the given collection are contained in this set.
      Parameters:
      a - the collection of elements to count.
      Returns:
      how many times the elements in the given collection are contained in this set.