public class SortedArrayList<E>
extends java.util.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 java.util.Comparator<E> |
comparator |
Constructor and Description |
---|
SortedArrayList()
Constructs a new
SortedArrayList expecting
elements are comparable. |
SortedArrayList(java.util.Collection<? extends E> c)
Constructs a new
SortedArrayList expecting
elements are comparable. |
SortedArrayList(java.util.Comparator<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) |
boolean |
addAll(java.util.Collection<? extends E> c)
Add all of the elements in the given collection to this list.
|
boolean |
addAll(int index,
java.util.Collection<? extends E> c) |
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 low,
int high)
Conducts a binary search to find the index where Object
should be inserted.
|
java.util.Comparator |
getComparator()
Returns comparator assigned to this collection, if such exist.
|
E |
set(int index,
E element) |
clear, clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, size, sort, spliterator, subList, toArray, toArray, trimToSize
protected final java.util.Comparator<E> comparator
public SortedArrayList(java.util.Comparator<E> c)
SortedArrayList
.public SortedArrayList()
SortedArrayList
expecting
elements are comparable.public SortedArrayList(java.util.Collection<? extends E> c)
SortedArrayList
expecting
elements are comparable.public java.util.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(java.util.Collection<? extends E> c)
public int findInsertionPoint(E o)
public void add(int index, E element)
public boolean addAll(int index, java.util.Collection<? extends E> c)
protected int compare(E k1, E k2)
protected int findInsertionPoint(E o, int low, int high)
Copyright © 2003-present Jodd Team