E
- The type of elements in this list.public class SortedList<E> extends ObservableList<E>
List
that guarantees sorted order of its elements.ObservableList.ObservableListIterator, ObservableList.ObservableSubList
target
modCount
Constructor and Description |
---|
SortedList(List<E> list,
Comparator<E> comparator)
|
SortedList(List<T> list)
Creates a new
SortedList with the provided list of
comparable elements as the underlying target. |
Modifier and Type | Method and Description |
---|---|
protected boolean |
beforeAdd(int index,
E element)
Callback method that is invoked immediately before an element is added to
the enclosed
List . |
protected boolean |
beforeSet(int index,
E newElement)
Callback method that is invoked immediately before an element is set at an
index in the enclosed
List . |
boolean |
containsAll(Collection<?> c) |
int |
indexOf(Object o) |
int |
lastIndexOf(Object o) |
ListIterator<E> |
listIterator(int index) |
boolean |
retainAll(Collection<?> c) |
SortedList<E> |
subList(int fromIndex,
int toIndex) |
add, add, addAll, addAll, addFast, afterAdd, afterGet, afterRemove, afterSet, beforeGet, beforeRemove, clear, contains, equals, forEach, get, getFast, hashCode, iterator, listIterator, newListIterator, newSubList, parallelStream, remove, remove, removeAll, removeFast, removeIf, replaceAll, set, size, sort, spliterator, stream, toArray, toArray, toString
isEmpty, superForEach, superParallelStream, superRemoveIf, superReplaceAll, superSort, superSpliterator, superStream
removeRange
public SortedList(List<T> list)
SortedList
with the provided list
of
comparable elements as the underlying target.
Note: This constructor sorts the provided list
.
T
- The parameter requiring elements of type Comparable<? super E>
.list
- The List
of comparable elements.NullPointerException
- If the provided list
is null.public SortedList(List<E> list, Comparator<E> comparator)
SortedList
with the provided list
and
comparator
as the underlying target.
Note: This constructor sorts the provided list
.
list
- The List
.comparator
- The Comparator
.NullPointerException
- If the provided list
or
comparator
is null.protected boolean beforeSet(int index, E newElement)
ObservableList
List
.
Note: It is possible for index
to be -1
, in case the
set operation is executed from an Iterator
when a prior
Iterator.remove()
or ListIterator.add(Object)
or
ListIterator.set(Object)
has already been called.
beforeSet
in class ObservableList<E>
index
- The index for the element to be set in the enclosed
List
.newElement
- The element to be set in the enclosed List
.true
, the subsequent set
operation will be performed; if this method returns false
,
the subsequent set operation will not be performed.protected boolean beforeAdd(int index, E element)
ObservableList
List
.
Note: It is possible for index
to be -1
, in case the
add operation is executed from an Iterator
when a prior
Iterator.remove()
or ListIterator.add(Object)
or
ListIterator.set(Object)
has already been called.
beforeAdd
in class ObservableList<E>
index
- The index for the element to be added to the enclosed
List
.element
- The element to be added to the enclosed List
.true
, the subsequent add
operation will be performed; if this method returns false
,
the subsequent add operation will not be performed.public boolean containsAll(Collection<?> c)
The callback methods ObservableList.beforeGet(int,ListIterator)
and
ObservableList.afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each member of the enclosed list is
referenced.
Runtime performance: O(log2(n) * m)
if the provided
collection is a SortedList
; otherwise O(n * m)
.
containsAll
in interface Collection<E>
containsAll
in interface List<E>
containsAll
in class ObservableList<E>
public boolean retainAll(Collection<?> c)
ObservableList
The callback methods ObservableList.beforeRemove(int)
and
ObservableList.afterRemove(Object,RuntimeException)
are called immediately before
and after the enclosed List
is modified for the removal of each
element not in the specified Collection
. All elements for which
ObservableList.beforeRemove(int)
returns false
will not be removed from
this List
.
retainAll
in interface Collection<E>
retainAll
in interface List<E>
retainAll
in class ObservableList<E>
public int indexOf(Object o)
The callback methods ObservableList.beforeGet(int,ListIterator)
and
ObservableList.afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each member of the enclosed list is
referenced.
Runtime performance: O(log2(n))
.
public int lastIndexOf(Object o)
The callback methods ObservableList.beforeGet(int,ListIterator)
and
ObservableList.afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each member of the enclosed list is
referenced.
Runtime performance: O(log2(n))
.
lastIndexOf
in interface List<E>
lastIndexOf
in class ObservableList<E>
public ListIterator<E> listIterator(int index)
Calling ListIterator.remove()
will delegate a callback to
ObservableList.beforeRemove(int)
and
ObservableList.afterRemove(Object,RuntimeException)
on this instance. All
elements for which ObservableList.beforeRemove(int)
returns false
will
not be removed from this List
. Calling
ListIterator.set(Object)
will delegate a callback to
ObservableList.beforeSet(int,Object)
and
ObservableList.afterSet(int,Object,RuntimeException)
on this instance. All
elements for which ObservableList.beforeSet(int,Object)
returns false
will not be set in this List
. Calling
ListIterator.add(Object)
will delegate a callback to
ObservableList.beforeAdd(int,Object)
and
ObservableList.afterAdd(int,Object,RuntimeException)
on this instance. All
elements for which ObservableList.beforeAdd(int,Object)
returns false
will not be added to this List
.
Note: The ListIterator
returned by this method does not
support ListIterator.add(Object)
or
ListIterator.set(Object)
.
listIterator
in interface List<E>
listIterator
in class ObservableList<E>
public SortedList<E> subList(int fromIndex, int toIndex)
DelegateList
The class DelegateList
does not itself implement
#subList(int,int)
, so calling this method on an instance of a
subclass of DelegateList
that does not override this method will
result in a UnsupportedOperationException
.
Copyright © 2020 LibJ. All rights reserved.