Package eu.simuline.util
Class TreeMultiSet<T>
- java.lang.Object
-
- eu.simuline.util.AbstractMultiSet<java.util.NavigableMap<T,MultiSet.Multiplicity>,T>
-
- eu.simuline.util.TreeMultiSet<T>
-
- Type Parameters:
T- the class of the elements of this multi-set.
- All Implemented Interfaces:
MultiSet<T>,SortedMultiSet<T>,java.lang.Iterable<T>
public final class TreeMultiSet<T> extends AbstractMultiSet<java.util.NavigableMap<T,MultiSet.Multiplicity>,T> implements SortedMultiSet<T>
Represents a sorted set with multiplicities based on aTreeMap. Mathematically this is something between a set and a family. Note that this kind of set does not supportnullelements.- Version:
- 1.0
- Author:
- Ernst Reissner
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class eu.simuline.util.AbstractMultiSet
AbstractMultiSet.MultiplicityImpl, AbstractMultiSet.MultiSetIteratorImpl<T>
-
Nested classes/interfaces inherited from interface eu.simuline.util.MultiSet
MultiSet.Multiplicity
-
-
Field Summary
-
Fields inherited from class eu.simuline.util.AbstractMultiSet
obj2mult
-
-
Constructor Summary
Constructors Modifier Constructor Description TreeMultiSet()Creates a new, emptyMultiSet.TreeMultiSet(MultiSet<? extends T> other)Copy constructor.TreeMultiSet(java.util.Comparator<? super T> comp)Creates a new, emptyMultiSet.privateTreeMultiSet(java.util.NavigableMap<T,MultiSet.Multiplicity> t2mult)TreeMultiSet(java.util.Set<? extends T> sSet)Creates a multi set with the elements ofsSetand all elements with multiplicity1.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Comparator<? super T>comparator()Returns the comparator used to order the elements in this set, ornullif this set uses the natural ordering of its elements.Tfirst()Returns the first (lowest) element currently in this set.java.util.NavigableMap<T,MultiSet.Multiplicity>getMap()Returns a view of the underlying map of thisSortedMultiSetas a map mapping each entry to its multiplicity.java.util.SortedSet<T>getSet()Returns a view of the underlying set of thisMultiSet.SortedMultiSet<T>headSet(T toElement)Returns a view of the portion of this multi-set whose elements are strictly less thantoElement.Tlast()Returns the last (highest) element currently in this set.SortedMultiSet<T>subSet(T fromElement, T toElement)Returns a view of the portion of this multi-set whose elements range fromfromElementinclusively totoElementexclusively.SortedMultiSet<T>tailSet(T fromElement)Returns a view of the portion of this multi-set whose elements are greater than or equal tofromElement.java.lang.StringtoString()-
Methods inherited from class eu.simuline.util.AbstractMultiSet
add, addAll, addAll, addWithMult, addWithMult, clear, contains, containsAll, equals, getMaxMult, getMultiplicity, getMultiplicityObj, getObjWithMaxMult, getSetWithMults, hashCode, isEmpty, iterator, remove, removeAll, removeWithMult, removeWithMult, retainAll, setMultiplicity, size, sizeWithMult, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface eu.simuline.util.MultiSet
add, addAll, addAll, addWithMult, addWithMult, clear, contains, containsAll, equals, getMaxMult, getMultiplicity, getMultiplicityObj, getObjWithMaxMult, getSetWithMults, hashCode, isEmpty, iterator, remove, removeAll, removeWithMult, removeWithMult, retainAll, setMultiplicity, size, sizeWithMult, toArray, toArray
-
-
-
-
Constructor Detail
-
TreeMultiSet
private TreeMultiSet(java.util.NavigableMap<T,MultiSet.Multiplicity> t2mult)
-
TreeMultiSet
public TreeMultiSet()
Creates a new, emptyMultiSet.
-
TreeMultiSet
public TreeMultiSet(java.util.Comparator<? super T> comp)
Creates a new, emptyMultiSet.
-
TreeMultiSet
public TreeMultiSet(MultiSet<? extends T> other)
Copy constructor.- Parameters:
other- anotherMultiSetinstance.
-
TreeMultiSet
public TreeMultiSet(java.util.Set<? extends T> sSet)
Creates a multi set with the elements ofsSetand all elements with multiplicity1.- Parameters:
sSet- some instance of a sorted set.
-
-
Method Detail
-
comparator
public java.util.Comparator<? super T> comparator()
Returns the comparator used to order the elements in this set, ornullif this set uses the natural ordering of its elements.- Specified by:
comparatorin interfaceSortedMultiSet<T>- Returns:
- the comparator used to order the elements in this set,
or
nullif this set uses the natural ordering of its elements.
-
first
public T first()
Returns the first (lowest) element currently in this set.- Specified by:
firstin interfaceSortedMultiSet<T>- Returns:
- the first (lowest) element currently in this set
- Throws:
java.util.NoSuchElementException- if this set is empty.
-
last
public T last()
Returns the last (highest) element currently in this set.- Specified by:
lastin interfaceSortedMultiSet<T>- Returns:
- the last (highest) element currently in this set.
- Throws:
java.util.NoSuchElementException- if this set is empty.
-
headSet
public SortedMultiSet<T> headSet(T toElement)
Returns a view of the portion of this multi-set whose elements are strictly less thantoElement. The returned multi-set is backed by this multi-set, so changes in the returned set are reflected in this multi-set, and vice-versa. The returned multi-set supports all optional multi-set operations that this multi-set supports.The returned multi-set will throw an
IllegalArgumentExceptionon an attempt to insert an element outside its range.- Specified by:
headSetin interfaceSortedMultiSet<T>- Parameters:
toElement- high endpoint (exclusive) of the returned multi-set.- Returns:
- a view of the portion of this multi-set
whose elements are strictly less than
toElement. - Throws:
java.lang.ClassCastException- iftoElementis not compatible with this multi-set's comparator (or, if the set has no comparator, iftoElementdoes not implementComparable). Implementations may, but are not required to, throw this exception iftoElementcannot be compared to elements currently in this multi-set.java.lang.NullPointerException- iftoElementisnulland this multi-set does not permitnullelements.java.lang.IllegalArgumentException- if this multi-set itself has a restricted range, andtoElementlies outside the bounds of the range.
-
tailSet
public SortedMultiSet<T> tailSet(T fromElement)
Returns a view of the portion of this multi-set whose elements are greater than or equal tofromElement. The returned multi-set is backed by this multi-set, so changes in the returned set are reflected in this multi-set, and vice-versa. The returned multi-set supports all optional multi-set operations that this multi-set supports.The returned multi-set will throw an
IllegalArgumentExceptionon an attempt to insert an element outside its range.- Specified by:
tailSetin interfaceSortedMultiSet<T>- Parameters:
fromElement- low endpoint (inclusive) of the returned multi-set.- Returns:
- a view of the portion of this multi-set
whose elements are greater than or equal to
fromElement. - Throws:
java.lang.ClassCastException- iffromElementis not compatible with this multi-set's comparator (or, if the set has no comparator, iffromElementdoes not implementComparable). Implementations may, but are not required to, throw this exception iffromElementcannot be compared to elements currently in this multi-set.java.lang.NullPointerException- iffromElementisnulland this multi-set does not permitnullelements.java.lang.IllegalArgumentException- if this multi-set itself has a restricted range, andfromElementlies outside the bounds of the range.
-
subSet
public SortedMultiSet<T> subSet(T fromElement, T toElement)
Returns a view of the portion of this multi-set whose elements range fromfromElementinclusively totoElementexclusively. The returned multi-set is backed by this multi-set, so changes in the returned set are reflected in this multi-set, and vice-versa. The returned multi-set supports all optional multi-set operations that this multi-set supports.The returned multi-set will throw an
IllegalArgumentExceptionon an attempt to insert an element outside its range.- Specified by:
subSetin interfaceSortedMultiSet<T>- Parameters:
fromElement- low endpoint (inclusive) of the returned multi-set.toElement- high endpoint (exclusive) of the returned multi-set.- Returns:
- a view of the portion of this multi-set
from
fromElementinclusively totoElementexclusively. - Throws:
java.lang.ClassCastException- **** maybe original documentation wrong. **** iffromElementandtoElementcannot be compared to one another using this set's comparator (or, if the set has no comparator, using natural ordering). or iffromElementis not compatible with this multi-set's comparator (or, if the set has no comparator, iffromElementdoes not implementComparable). Implementations may, but are not required to, throw this exception iffromElementortoElementcannot be compared to elements currently in this multi-set.java.lang.NullPointerException- iffromElementortoElementisnulland this multi-set does not permitnullelements.java.lang.IllegalArgumentException- iffromElementis greater thantoElementor if this multi-set itself has a restricted range, andfromElementortoElementlies outside the bounds of the range.
-
getSet
public java.util.SortedSet<T> getSet()
Returns a view of the underlying set of thisMultiSet. For certain implementations, this set is immutable to prevent implicit modification of thisMultiSet.
-
getMap
public java.util.NavigableMap<T,MultiSet.Multiplicity> getMap()
Returns a view of the underlying map of thisSortedMultiSetas a map mapping each entry to its multiplicity.
-
-