Class AbstractMultiSet<T,M extends Map<T,Integer>>

java.lang.Object
java.util.AbstractCollection<T>
org.processmining.framework.util.collection.AbstractMultiSet<T,M>
Type Parameters:
T - the type of the objects in this multiset.
All Implemented Interfaces:
Iterable<T>, Collection<T>, MultiSet<T>, HTMLToString
Direct Known Subclasses:
HashMultiSet, TreeMultiSet

public abstract class AbstractMultiSet<T,M extends Map<T,Integer>> extends AbstractCollection<T> implements MultiSet<T>
This class implements a mutliset. The implementation is synchronized.
Author:
bfvdonge
  • Field Details

    • map

      protected M extends Map<T,Integer> map
    • size

      protected int size
  • Constructor Details

    • AbstractMultiSet

      public AbstractMultiSet()
  • Method Details

    • retainAll

      public boolean retainAll(Collection<?> c)
      Keeps all elements of the given collection in this multiset. Multicities are taken into account, i.e. as many of the same objects are kept as returned by the collections iterator.
      Specified by:
      retainAll in interface Collection<T>
      Overrides:
      retainAll in class AbstractCollection<T>
      Returns:
      true if the multiset changed from calling this method.
    • add

      public boolean add(T par)
      adds one object to the multiset. If the object was not contained before, then it now has one occerrence, otherwise, the number of occurrences is increased.
      Specified by:
      add in interface Collection<T>
      Overrides:
      add in class AbstractCollection<T>
      Returns:
      true, since the collection is always modified.
    • retainAll

      public boolean retainAll(MultiSet<?> c)
      Keeps all elements of the given collection in this multiset. Multiplicities are taken into account.
      Returns:
      true if the multiset changed from calling this method.
    • add

      public Integer add(T par, Integer weight)
      Adds the given object to the multiset, as many times as indicated by the given weight parameter.
      Specified by:
      add in interface MultiSet<T>
      Parameters:
      par - the object to add
      weight - the number of times to add it
      Returns:
      the new number of occurrences of the object (>0)
    • addAll

      public boolean addAll(Collection<? extends T> collection)
      Adds the given collection to this multiset. If the given collection is not a multiset, then the implementation is diverted to abstractcollection.
      Specified by:
      addAll in interface Collection<T>
      Overrides:
      addAll in class AbstractCollection<T>
      Parameters:
      collection - the collection to add
      Returns:
      true if the multiset changed due to this method call.
    • toList

      public List<T> toList()
      Converts this multiset to a list, such that each element occurs as often as returned by the iterator of the multiset (its number of occurrences).
      Specified by:
      toList in interface MultiSet<T>
      Returns:
      a list of objects as returned by the iterator
    • isLessOrEqual

      public boolean isLessOrEqual(MultiSet<T> multiSet)
      returns true if this multiset is less or equal to the given multiset, i.e. all objects in this multiset should be contained in the given set and the number of occurrences in the given set is at least the number of occurrences in this multiset.
      Specified by:
      isLessOrEqual in interface MultiSet<T>
      Parameters:
      multiSet - the multiset to test
      Returns:
      true if the given multiset is less or equal.
    • containsAtLeast

      protected boolean containsAtLeast(T element, int occ)
    • equals

      public boolean equals(Object o)
      returns true if the multisets are equal, i.e. if they contain the same objects with the same number of occurrences.
      Specified by:
      equals in interface Collection<T>
      Overrides:
      equals in class Object
    • size

      public int size()
      returns the size of the multiset, i.e. the sum over the multiplicities of all contained objects.
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in class AbstractCollection<T>
    • toString

      public String toString()
      returns a string representing this multiset. The string contains, between brackets, pairs of objects and their multiplicities.
      Overrides:
      toString in class AbstractCollection<T>
    • hashCode

      public int hashCode()
      returns a hashCode for this multiset.
      Specified by:
      hashCode in interface Collection<T>
      Overrides:
      hashCode in class Object
    • occurrences

      public Integer occurrences(Object source)
      returns the number of occurrences of the given object in this multiset.
      Specified by:
      occurrences in interface MultiSet<T>
      Parameters:
      source - the object to get the occurrences for
      Returns:
      the number of occurrences, 0 if the object does not occur.
    • iterator

      public Iterator<T> iterator()
      returns an iterator over the elements of the multiset. Note that if an object appears n times in the multiset, it is returned n times by the iterator. For an iterator over unique elements of the multiset, use the toSet() method.
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in class AbstractCollection<T>
    • baseSet

      public Set<T> baseSet()
      returns an unmodifiable set of unique objects in the multiset.
      Specified by:
      baseSet in interface MultiSet<T>
      Returns:
      an unmodifiable set of unique objects in the multiset.
    • contains

      public boolean contains(Object o)
      checks whether the number of occurrences of the given object is greater or equal to 1.
      Specified by:
      contains in interface Collection<T>
      Overrides:
      contains in class AbstractCollection<T>
    • containsAll

      public boolean containsAll(Collection<?> c)
      Checks whether the number of occurrences of elements in the given collection is at most what is specified in this collection, i.e., this method returns (new MultiSet(c)).isLessOrEqual(this)
      Specified by:
      containsAll in interface Collection<T>
      Overrides:
      containsAll in class AbstractCollection<T>
    • remove

      public boolean remove(Object o)
      removes the given object from this multiset, if it is in there. Only one occurrence is removed, i.e. contains(o) can still be true after calling remove(o)
      Specified by:
      remove in interface Collection<T>
      Overrides:
      remove in class AbstractCollection<T>
    • removeAll

      public boolean removeAll(Collection<?> collection)
      removes the elements in the given multiset from this multiset.
      Specified by:
      removeAll in interface Collection<T>
      Overrides:
      removeAll in class AbstractCollection<T>
      Parameters:
      mset - the multiset of elements needing to be removed.
      Returns:
      a new multiset where the occurrences are the occurrences in this multiset, minus the occurrences in the given multiset
    • removeAllMultiSet

      protected <S extends MultiSet<T>> S removeAllMultiSet(AbstractMultiSet<?,?> mset, S removed)
    • toHTMLString

      public String toHTMLString(boolean includeHTMLTags)
      Specified by:
      toHTMLString in interface HTMLToString
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<T>
      Overrides:
      clear in class AbstractCollection<T>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<T>
      Overrides:
      isEmpty in class AbstractCollection<T>