Class AbstractMultiSet<T,M extends java.util.Map<T,java.lang.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:
java.lang.Iterable<T>
,java.util.Collection<T>
,MultiSet<T>
,HTMLToString
- Direct Known Subclasses:
HashMultiSet
,TreeMultiSet
public abstract class AbstractMultiSet<T,M extends java.util.Map<T,java.lang.Integer>> extends java.util.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
-
-
Constructor Summary
Constructors Constructor Description AbstractMultiSet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(T par)
adds one object to the multiset.java.lang.Integer
add(T par, java.lang.Integer weight)
Adds the given object to the multiset, as many times as indicated by the given weight parameter.boolean
addAll(java.util.Collection<? extends T> collection)
Adds the given collection to this multiset.java.util.Set<T>
baseSet()
returns an unmodifiable set of unique objects in the multiset.void
clear()
boolean
contains(java.lang.Object o)
checks whether the number of occurrences of the given object is greater or equal to 1.boolean
containsAll(java.util.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
equals(java.lang.Object o)
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.java.util.Iterator<T>
iterator()
returns an iterator over the elements of the multiset.java.lang.Integer
occurrences(java.lang.Object source)
returns the number of occurrences of the given object in this multiset.boolean
remove(java.lang.Object o)
removes the given object from this multiset, if it is in there.boolean
removeAll(java.util.Collection<?> collection)
removes the elements in the given multiset from this multiset.protected <S extends MultiSet<T>>
SremoveAllMultiSet(AbstractMultiSet<?,?> mset, S removed)
boolean
retainAll(java.util.Collection<?> c)
Keeps all elements of the given collection in this multiset.boolean
retainAll(MultiSet<?> c)
Keeps all elements of the given collection in this multiset.int
size()
returns the size of the multiset, i.e.java.lang.String
toHTMLString(boolean includeHTMLTags)
java.util.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).java.lang.String
toString()
returns a string representing this multiset.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
retainAll
public boolean retainAll(java.util.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.
-
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.
-
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 java.lang.Integer add(T par, java.lang.Integer weight)
Adds the given object to the multiset, as many times as indicated by the given weight parameter.
-
addAll
public boolean addAll(java.util.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.
-
toList
public java.util.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).
-
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 interfaceMultiSet<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(java.lang.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 interfacejava.util.Collection<T>
- Overrides:
equals
in classjava.lang.Object
-
size
public int size()
returns the size of the multiset, i.e. the sum over the multiplicities of all contained objects.
-
toString
public java.lang.String toString()
returns a string representing this multiset. The string contains, between brackets, pairs of objects and their multiplicities.- Overrides:
toString
in classjava.util.AbstractCollection<T>
-
hashCode
public int hashCode()
returns a hashCode for this multiset.- Specified by:
hashCode
in interfacejava.util.Collection<T>
- Overrides:
hashCode
in classjava.lang.Object
-
occurrences
public java.lang.Integer occurrences(java.lang.Object source)
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
public java.util.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.
-
baseSet
public java.util.Set<T> baseSet()
returns an unmodifiable set of unique objects in the multiset.
-
contains
public boolean contains(java.lang.Object o)
checks whether the number of occurrences of the given object is greater or equal to 1.
-
containsAll
public boolean containsAll(java.util.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)
-
remove
public boolean remove(java.lang.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)
-
removeAll
public boolean removeAll(java.util.Collection<?> collection)
removes the elements in the given multiset from this multiset.- Specified by:
removeAll
in interfacejava.util.Collection<T>
- Overrides:
removeAll
in classjava.util.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 java.lang.String toHTMLString(boolean includeHTMLTags)
- Specified by:
toHTMLString
in interfaceHTMLToString
-
clear
public void clear()
-
-