E - type of elements stored in the listpublic class GapList<E> extends IList<E>
Note that this implementation is not synchronized.
Note that the iterators provided are not fail-fast.
List,
ArrayList,
LinkedList,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
protected static class |
GapList.ImmutableGapList<E>
An immutable version of a GapList.
|
IList.IReadOnlyList<E>, IList.IReadOnlyListFromArray<E>, IList.IReadOnlyListFromCollection<E>, IList.IReadOnlyListFromList<E>, IList.IReadOnlyListFromMult<E>| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_CAPACITY
Default capacity for list
|
| Modifier | Constructor and Description |
|---|---|
|
GapList()
Construct a list with the default initial capacity.
|
protected |
GapList(boolean copy,
GapList<E> that)
Constructor used internally, e.g. for ImmutableGapList.
|
|
GapList(java.util.Collection<? extends E> coll)
Construct a list to contain the specified elements.
|
|
GapList(int capacity)
Construct a list with specified initial capacity.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E elem) |
void |
add(int index,
E elem) |
<K> int |
binarySearch(int index,
int len,
K key,
java.util.Comparator<? super K> comparator)
Searches the specified range for an object using the binary search algorithm.
|
int |
capacity()
Returns capacity of this list.
|
java.lang.Object |
clone()
Returns a shallow copy of this list.
|
GapList<E> |
copy()
Returns a shallow copy of this list.
|
static <E> GapList<E> |
create()
Create new list.
|
static <E> GapList<E> |
create(java.util.Collection<? extends E> coll)
Create new list with specified elements.
|
static <E> GapList<E> |
create(E... elems)
Create new list with specified elements.
|
protected boolean |
doAdd(int index,
E elem)
Helper method for adding an element to the list.
|
protected void |
doAssign(IList<E> that)
Assign this list the content of the that list.
|
protected void |
doClear() |
protected void |
doClone(IList<E> that)
Initialize this object after the bitwise copy has been made by Object.clone().
|
GapList<E> |
doCreate(int capacity)
Create list with specified capacity.
|
protected void |
doEnsureCapacity(int minCapacity)
Increases the capacity of this list instance, if
necessary, to ensure that it can hold at least the number of elements
specified by the minimum capacity argument.
|
protected E |
doGet(int index)
Helper method for getting an element from the list.
|
protected <T> void |
doGetAll(T[] array,
int index,
int len)
Helper method to fill the specified elements in an array.
|
protected E |
doRemove(int index)
Helper method to remove an element.
|
protected void |
doRemoveAll(int index,
int len)
Remove specified range of elements from list.
|
protected boolean |
doRemoveAllFast(int index,
int len)
Remove specified range of elements from list as specialized fast operation.
|
protected E |
doReSet(int index,
E elem)
Sets an element at specified position.
|
protected E |
doSet(int index,
E elem)
Helper method for setting an element in the list.
|
static <EE> GapList<EE> |
EMPTY() |
void |
ensureCapacity(int minCapacity)
Increases the capacity of this GapList instance, if necessary, to ensure that it can hold at least the number of elements
specified by the minimum capacity argument.
|
E |
get(int index) |
GapList<E> |
getAll(E elem)
Returns all elements in the list equal to the specified element.
|
GapList<E> |
getAll(int index,
int len)
Returns specified range of elements from list.
|
E |
getDefaultElem() |
<R> GapList<R> |
mappedList(java.util.function.Function<E,R> mapper)
Create a new list by applying the specified mapping function to all elements.
|
E |
remove(int index) |
int |
size() |
void |
sort(int index,
int len,
java.util.Comparator<? super E> comparator)
Sort specified elements in the list using the specified comparator.
|
void |
trimToSize()
Trims the capacity of this GapList instance to be the list's current size.
|
GapList<E> |
unmodifiableList()
Returns an unmodifiable view of this list.
|
addAll, addAll, addAll, addAll, addArray, addArray, addArray, addArray, addFirst, addIfAbsent, addLast, addMult, addMult, binarySearch, checkIndex, checkIndexAdd, checkLength, checkLengths, checkNonNull, checkRange, clear, contains, containsAll, containsAny, containsIf, copy, descendingIterator, doAddAll, doCreateArray, doModify, doReplaceAll, doRotate, drag, element, equals, extract, extractIf, fill, filter, filteredList, getCount, getDistinct, getFirst, getIf, getLast, getSingle, getSingleOrEmpty, hashCode, indexOf, indexOf, indexOfIf, initAll, initAll, initArray, initMult, isEmpty, iterator, lastIndexOf, lastIndexOf, listIterator, listIterator, move, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, put, putAll, putAll, putArray, putMult, remove, remove, remove, removeAll, removeAll, removeAll, removeFirst, removeFirstOccurrence, removeIf, removeLast, removeLastOccurrence, replaceAll, replaceAll, replaceArray, replaceMult, resize, retainAll, retainAll, retainIf, reverse, reverse, rotate, rotate, set, setAll, setAll, setArray, setArray, setMult, sort, swap, toArray, toArray, toArray, toArray, toArray, toArray, toString, transferCopy, transferMove, transferRemove, transferSwap, transform, transformedListpublic static final int DEFAULT_CAPACITY
protected GapList(boolean copy,
GapList<E> that)
copy - true to copy all instance values from source, if false nothing is donethat - list to copypublic GapList()
public GapList(int capacity)
capacity - capacitypublic GapList(java.util.Collection<? extends E> coll)
coll - collection with elementspublic static <EE> GapList<EE> EMPTY()
public static <E> GapList<E> create()
E - type of elements stored in the listpublic static <E> GapList<E> create(java.util.Collection<? extends E> coll)
E - type of elements stored in the listcoll - collection with element@SafeVarargs public static <E> GapList<E> create(E... elems)
E - type of elements stored in the listelems - array with elementsprotected void doAssign(IList<E> that)
IListpublic E getDefaultElem()
getDefaultElem in class IList<E>public GapList<E> copy()
IListpublic java.lang.Object clone()
IListpublic void ensureCapacity(int minCapacity)
ensureCapacity in class IList<E>minCapacity - the desired minimum capacitypublic GapList<E> unmodifiableList()
IListunmodifiableList in class IList<E>protected void doClone(IList<E> that)
IListpublic int size()
public int capacity()
IListpublic E get(int index)
protected E doGet(int index)
IListprotected E doSet(int index, E elem)
IListprotected E doReSet(int index, E elem)
IListpublic boolean add(E elem)
public void add(int index,
E elem)
public GapList<E> getAll(int index, int len)
IListpublic GapList<E> getAll(E elem)
IListpublic <R> GapList<R> mappedList(java.util.function.Function<E,R> mapper)
IListmappedList in class IList<E>mapper - mapping functionprotected boolean doAdd(int index,
E elem)
IListpublic E remove(int index)
protected E doRemove(int index)
IListprotected void doEnsureCapacity(int minCapacity)
IListdoEnsureCapacity in class IList<E>minCapacity - the desired minimum capacitypublic void trimToSize()
trimToSize in class IList<E>protected <T> void doGetAll(T[] array,
int index,
int len)
IListpublic GapList<E> doCreate(int capacity)
IListprotected void doRemoveAll(int index,
int len)
IListdoRemoveAll in class IList<E>index - index of first element to removelen - number of elements to removeprotected boolean doRemoveAllFast(int index,
int len)
index - index of first element to removelen - number of elements to removepublic void sort(int index,
int len,
java.util.Comparator<? super E> comparator)
IListpublic <K> int binarySearch(int index,
int len,
K key,
java.util.Comparator<? super K> comparator)
IListNote that the method is defined to work with an arbitrary type <K>. This allows to search directly for a key field in the object without the need to construct an object containing the key:
persons.binarySearch("john", new SearchByName());
class SearchByName implements Comparator<Object> {
public int compare(Object o1, Object o2) {
String s1 = (o1 instanceof String) ? (String) o1 : ((Name) o1).getName();
String s2 = (o2 instanceof String) ? (String) o2 : ((Name) o2).getName();
return s1.compareTo(s2);
}
}
/binarySearch in class IList<E>index - index of first element to searchlen - number of elements to searchkey - the value to be searched forcomparator - the comparator by which the list is ordered.
A null value indicates that the elements'
natural ordering should be used.Arrays.binarySearch(long[], long)