T
- The type of objectpublic class BoundedTreeSet<T> extends TreeSet<T>
TreeSet
that has a bounded upper size.
Once this size is reached new objects will only be added if they
are less than the last element in the set (according to the @{Comparable}
interface or the given Comparator
). If the new object
is eligable to be added, the last item is automatically removed.
Note: do not use this class as a form of priority queue if you
expect items with equal priorities. Because this class is a form
of set, items with equal priorities would be considered equal,
an only one of them would be admitted to the set.Modifier and Type | Field and Description |
---|---|
protected int |
maxSize |
Constructor and Description |
---|
BoundedTreeSet(int maxSize)
Constructs a new, empty tree set, sorted according to the
natural ordering of its elements.
|
BoundedTreeSet(int maxSize,
Comparator<? super T> comparator)
Constructs a new, empty tree set, sorted according to the specified
comparator.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(T e) |
boolean |
addAll(Collection<? extends T> c) |
ceiling, clear, clone, comparator, contains, descendingIterator, descendingSet, first, floor, headSet, headSet, higher, isEmpty, iterator, last, lower, pollFirst, pollLast, remove, size, spliterator, subSet, subSet, tailSet, tailSet
equals, hashCode, removeAll
containsAll, retainAll, toArray, toArray, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
parallelStream, removeIf, stream
protected int maxSize
public BoundedTreeSet(int maxSize)
Comparable
interface.
Furthermore, all such elements must be mutually
comparable: e1.compareTo(e2)
must not throw a
ClassCastException
for any elements e1
and
e2
in the set. If the user attempts to add an element
to the set that violates this constraint (for example, the user
attempts to add a string element to a set whose elements are
integers), the add
call will throw a
ClassCastException
.
The set additionally has a maximum size. Once this size is reached
new objects will only be added if they are less than the last element
in the set (according to the @{Comparable} interface). If the new object
is eligable to be added, the last item is automatically removed.maxSize
- The maximum allowed number of elements.public BoundedTreeSet(int maxSize, Comparator<? super T> comparator)
comparator.compare(e1,
e2)
must not throw a ClassCastException
for any elements
e1
and e2
in the set. If the user attempts to add
an element to the set that violates this constraint, the
add
call will throw a ClassCastException
.
The set additionally has a maximum size. Once this size is reached
new objects will only be added if they are less than the last element
in the set (according to the @{Comparable} interface). If the new object
is eligable to be added, the last item is automatically removed.maxSize
- The maximum allowed number of elements.comparator
- the comparator that will be used to order this set.
If null
, the natural
ordering of the elements will be used.