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
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.processmining.framework.util.HTMLToString
HTMLToString.HTMLCellRenderer
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
adds one object to the multiset.Adds the given object to the multiset, as many times as indicated by the given weight parameter.boolean
addAll
(Collection<? extends T> collection) Adds the given collection to this multiset.baseSet()
returns an unmodifiable set of unique objects in the multiset.void
clear()
boolean
checks whether the number of occurrences of the given object is greater or equal to 1.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)protected boolean
containsAtLeast
(T element, int occ) boolean
returns true if the multisets are equal, i.e.int
hashCode()
returns a hashCode for this multiset.boolean
isEmpty()
boolean
isLessOrEqual
(MultiSet<T> multiSet) returns true if this multiset is less or equal to the given multiset, i.e.iterator()
returns an iterator over the elements of the multiset.occurrences
(Object source) returns the number of occurrences of the given object in this multiset.boolean
removes the given object from this multiset, if it is in there.boolean
removeAll
(Collection<?> collection) removes the elements in the given multiset from this multiset.removeAllMultiSet
(AbstractMultiSet<?, ?> mset, S removed) boolean
retainAll
(Collection<?> c) Keeps all elements of the given collection in this multiset.boolean
Keeps all elements of the given collection in this multiset.int
size()
returns the size of the multiset, i.e.toHTMLString
(boolean includeHTMLTags) 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).toString()
returns a string representing this multiset.Methods inherited from class java.util.AbstractCollection
toArray, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray, toArray, toArray
-
Field Details
-
map
-
size
protected int size
-
-
Constructor Details
-
AbstractMultiSet
public AbstractMultiSet()
-
-
Method Details
-
retainAll
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 interfaceCollection<T>
- Overrides:
retainAll
in classAbstractCollection<T>
- Returns:
- true if the multiset changed from calling this method.
-
add
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 interfaceCollection<T>
- Overrides:
add
in classAbstractCollection<T>
- Returns:
- true, since the collection is always modified.
-
retainAll
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
Adds the given object to the multiset, as many times as indicated by the given weight parameter. -
addAll
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 interfaceCollection<T>
- Overrides:
addAll
in classAbstractCollection<T>
- Parameters:
collection
- the collection to add- Returns:
- true if the multiset changed due to this method call.
-
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). -
isLessOrEqual
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 interfaceMultiSet<T>
- Parameters:
multiSet
- the multiset to test- Returns:
- true if the given multiset is less or equal.
-
containsAtLeast
-
equals
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 interfaceCollection<T>
- Overrides:
equals
in classObject
-
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 interfaceCollection<T>
- Specified by:
size
in classAbstractCollection<T>
-
toString
returns a string representing this multiset. The string contains, between brackets, pairs of objects and their multiplicities.- Overrides:
toString
in classAbstractCollection<T>
-
hashCode
public int hashCode()returns a hashCode for this multiset.- Specified by:
hashCode
in interfaceCollection<T>
- Overrides:
hashCode
in classObject
-
occurrences
returns the number of occurrences of the given object in this multiset.- Specified by:
occurrences
in interfaceMultiSet<T>
- Parameters:
source
- the object to get the occurrences for- Returns:
- the number of occurrences, 0 if the object does not occur.
-
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 interfaceCollection<T>
- Specified by:
iterator
in interfaceIterable<T>
- Specified by:
iterator
in classAbstractCollection<T>
-
baseSet
returns an unmodifiable set of unique objects in the multiset. -
contains
checks whether the number of occurrences of the given object is greater or equal to 1.- Specified by:
contains
in interfaceCollection<T>
- Overrides:
contains
in classAbstractCollection<T>
-
containsAll
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 interfaceCollection<T>
- Overrides:
containsAll
in classAbstractCollection<T>
-
remove
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 interfaceCollection<T>
- Overrides:
remove
in classAbstractCollection<T>
-
removeAll
removes the elements in the given multiset from this multiset.- Specified by:
removeAll
in interfaceCollection<T>
- Overrides:
removeAll
in classAbstractCollection<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
-
toHTMLString
- Specified by:
toHTMLString
in interfaceHTMLToString
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<T>
- Overrides:
clear
in classAbstractCollection<T>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<T>
- Overrides:
isEmpty
in classAbstractCollection<T>
-