public class SortedList<T> extends ArrayList<T>
List
which sorts its elements according to a certain order.
The natural sorting order of the elements is used unless a Comparator
was given
in the constructor.
The SortedList does not allow null
elements or duplicate elements. An
element is considered equal if Object.equals(Object)
returns true
.
Note that a SortedList is not synchronized! Use
Collections.synchronizedList(java.util.List)
if you need synchronized access.
modCount
Constructor and Description |
---|
SortedList()
Creates an empty SortedList with natural order.
|
SortedList(Collection<? extends T> col)
Creates a new SortedList and initialize it with the given
Collection . |
SortedList(Comparator<T> c)
Creates a SortedList that uses the given
Comparator instead of the
element's natural order. |
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
T element)
Adds an element to a certain index of this list.
|
boolean |
add(T elem)
Adds an element to the SortedList.
|
boolean |
addAll(Collection<? extends T> c)
Adds all elements of a
Collection to the SortedList. |
boolean |
addAll(int index,
Collection<? extends T> c)
Adds all elements of a
Collection to the SortedList, starting at a certain
index. |
Comparator<T> |
comparator()
Gets the
Comparator used for comparison, or null if natural order
is to be used. |
boolean |
contains(Object elem)
Checks if a SortedList contains an element.
|
int |
indexOf(Object elem)
Gets the index of an element.
|
int |
lastIndexOf(Object elem)
Gets the index of the last occurance of an element.
|
T |
set(int index,
T element)
This method is not supported by a SortedList.
|
clear, clone, ensureCapacity, forEach, get, isEmpty, iterator, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, size, sort, spliterator, subList, toArray, toArray, trimToSize
equals, hashCode
containsAll, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
containsAll, equals, hashCode
parallelStream, stream
public SortedList()
public SortedList(Collection<? extends T> col)
Collection
. The
collection entries are inserted as they are found in the Collection
, and
will be properly sorted in this list even if the Collection
was unsorted.col
- Collection
to initialize the SortedList with.public SortedList(Comparator<T> c)
Comparator
instead of the
element's natural order. Note that once set, a Comparator
cannot be changed
or removed.c
- Comparator to be usedpublic Comparator<T> comparator()
Comparator
used for comparison, or null
if natural order
is to be used.null
public void add(int index, T element)
public boolean add(T elem)
null
element is not permitted in a SortedList,
and will throw a NullPointerException
.add
in interface Collection<T>
add
in interface List<T>
add
in class ArrayList<T>
elem
- Element to be added.ClassCastException
Collection.add(java.lang.Object)
public boolean addAll(int index, Collection<? extends T> c)
Collection
to the SortedList, starting at a certain
index. This method is not permitted in a SortedList and thus throws an exception.public boolean addAll(Collection<? extends T> c)
Collection
to the SortedList. The entries are
inserted as they are found in the Collection
, and sorted to their proper
position.addAll
in interface Collection<T>
addAll
in interface List<T>
addAll
in class ArrayList<T>
c
- Collection to be added.Collection.addAll(java.util.Collection)
public boolean contains(Object elem)
true
to one of the elements in this
list.public int lastIndexOf(Object elem)
indexOf(Object)
.lastIndexOf
in interface List<T>
lastIndexOf
in class ArrayList<T>
elem
- Element to be foundCopyright © 2004–2016. All rights reserved.