public final class SortedArrayList<E> extends ArrayList<E>
修改包括:改进Comparator泛型定义,findInsertionPoint的位移改进
https://github.com/oblac/jodd/blob/master/jodd-core/src/main/java/jodd/util/collection/SortedArrayList.java
An extension of 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.
copy from vipshop VJTools
| 限定符和类型 | 字段和说明 |
|---|---|
protected Comparator<? super E> |
comparator |
modCount| 构造器和说明 |
|---|
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. |
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
add(E o)
Adds an Object to sorted list.
|
void |
add(int index,
E element)
已过时。
|
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)
已过时。
|
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)
已过时。
|
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, trimToSizeequals, hashCodecontainsAll, toStringcontainsAll, equals, hashCodeparallelStream, streamprotected final Comparator<? super E> comparator
public SortedArrayList(Comparator<? super E> c)
SortedArrayList.c - Comparatorpublic SortedArrayList()
SortedArrayList expecting
elements are comparable.public SortedArrayList(Collection<? extends E> c)
SortedArrayList expecting
elements are comparable.c - Collectionpublic 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)
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)
k1 - k2 - protected int findInsertionPoint(E o, int originalLow, int originalHigh)
o - originalLow - originalHigh - Copyright © 2019. All rights reserved.