public final class SortedArrayList<E> extends ArrayList<E>
ArrayList that insures that all of the items
added are sorted. This breaks original list contract!.
A binary search method is used to provide a quick way to
auto sort this list.Note: Not all methods for adding and
removing elements are supported.| Modifier and Type | Field and Description |
|---|---|
protected Comparator<? super E> |
comparator |
modCount| Constructor and Description |
|---|
SortedArrayList()
Constructs a new
SortedArrayList expecting
elements are comparable. |
SortedArrayList(Collection<? extends E> c)
Constructs a new
SortedArrayList expecting
elements are comparable. |
SortedArrayList(Comparator<? super E> c)
Constructs a new
SortedArrayList. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E o)
Adds an Object to sorted list.
|
void |
add(int index,
E element)
Deprecated.
|
boolean |
addAll(Collection<? extends E> c)
Add all of the elements in the given collection to this list.
|
boolean |
addAll(int index,
Collection<? extends E> c)
Deprecated.
|
protected int |
compare(E k1,
E k2)
Compares two keys using the correct comparison method for this
collection.
|
int |
findInsertionPoint(E o)
Finds the index at which object should be inserted.
|
protected int |
findInsertionPoint(E o,
int originalLow,
int originalHigh)
Conducts a binary search to find the index where Object
should be inserted.
|
Comparator |
getComparator()
Returns comparator assigned to this collection, if such exist.
|
E |
set(int index,
E element)
Deprecated.
|
clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeRange, retainAll, size, subList, toArray, toArray, trimToSizeequals, hashCodecontainsAll, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitcontainsAll, equals, hashCodeprotected final Comparator<? super E> comparator
public SortedArrayList(Comparator<? super E> c)
SortedArrayList.public SortedArrayList()
SortedArrayList expecting
elements are comparable.public SortedArrayList(Collection<? extends E> c)
SortedArrayList expecting
elements are comparable.public Comparator getComparator()
public boolean add(E o)
This method breaks original list contract since objects are not added at the list end, but in sorted manner.
public boolean addAll(Collection<? extends E> c)
public int findInsertionPoint(E o)
@Deprecated public void add(int index, E element)
@Deprecated public E set(int index, E element)
@Deprecated public boolean addAll(int index, Collection<? extends E> c)
protected int compare(E k1, E k2)
protected int findInsertionPoint(E o, int originalLow, int originalHigh)
Copyright © 2018. All rights reserved.