Class AbstractMultiset<A>

java.lang.Object
eu.bandm.tools.util.multi.AbstractMultiset<A>
Type Parameters:
A - type of the contained elements
All Implemented Interfaces:
Multiset<A>, Serializable, Iterable<A>
Direct Known Subclasses:
HashMultiset, TreeMultiset

public abstract class AbstractMultiset<A> extends Object implements Multiset<A>
Common superclass for sorted and unsorted domains.
See Also:
  • Constructor Details

    • AbstractMultiset

      protected AbstractMultiset()
      Only constructor
  • Method Details

    • map

      protected abstract Map<A,Integer> map()
      Returns the supporting map. That map Realizes containment by mapping every contained object to a number greater than zero, how often it is contained in this instance.
      Returns:
      the supporting map.
    • isEmpty

      public boolean isEmpty()
      Returns whether this set is empty.
      Specified by:
      isEmpty in interface Multiset<A>
      Returns:
      whether this set is empty.
    • clear

      public void clear()
      Remove all objects from this instance.
      Specified by:
      clear in interface Multiset<A>
    • xget

      protected int xget(Object a)
      Returns how often the given object is contained in this set, including zero times.
      Parameters:
      a - the object to test
      Returns:
      how often the given object is contained in this set, including zero times.
    • add

      public boolean add(A a)
      Add one element once to this set. This means to increase the number of contained elements by one.
      Specified by:
      add in interface Multiset<A>
      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.
    • add

      public 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.
      Specified by:
      add in interface Multiset<A>
      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.
    • contains

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

      public boolean containsUnchecked(Object a)
      Returns whether a particular element is contained at least once in this set.
      Specified by:
      containsUnchecked in interface Multiset<A>
      Parameters:
      a - element to test.
      Returns:
      whether a the given element is contained at least once in this set.
    • remove

      public 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.
      Specified by:
      remove in interface Multiset<A>
      Parameters:
      a - element to remove.
      Returns:
      whether this instance has changed.
    • removeUnchecked

      public 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.
      Specified by:
      removeUnchecked in interface Multiset<A>
      Parameters:
      a - element to remove.
      Returns:
      whether this instance has changed.
    • removeDomain

      public boolean removeDomain(A a)
      Remove the given element completely from this set.
      Specified by:
      removeDomain in interface Multiset<A>
      Parameters:
      a - element to remove.
      Returns:
      whether this instance has changed.
    • removeDomainUnchecked

      public boolean removeDomainUnchecked(Object a)
      Remove the given element completely from this set.
      Specified by:
      removeDomainUnchecked in interface Multiset<A>
      Parameters:
      a - element to remove.
      Returns:
      whether this instance has changed.
    • removeAll

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

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

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

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

      public int count(A o)
      Returns how many times the given element is contained in this set.
      Specified by:
      count in interface Multiset<A>
      Parameters:
      o - the element to test.
      Returns:
      how many times the given element is contained in this set.
    • countUnchecked

      public int countUnchecked(Object o)
      Returns how many times the given element is contained in this set.
      Specified by:
      countUnchecked in interface Multiset<A>
      Parameters:
      o - the element to test.
      Returns:
      how many times the given element is contained in this set.
    • countAll

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

      public int countAllUnchecked(Collection<?> c)
      Sum up how many times the elements in the given collection are contained in this set.
      Specified by:
      countAllUnchecked in interface Multiset<A>
      Parameters:
      c - the collection of elements to count.
      Returns:
      how many times the elements in the given collection are contained in this set.
    • iterator

      public Iterator<A> iterator()
      Specified by:
      iterator in interface Iterable<A>
    • domain

      public 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.
      Specified by:
      domain in interface Multiset<A>
      Returns:
      the set of all elements contained at least once in this instance.
    • supportMap

      public 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.
      Specified by:
      supportMap in interface Multiset<A>
      Returns:
      a map which assigns each element contained at least once in this instance to how often it is contained.
    • toString

      public String toString()
      Overrides:
      toString in class Object