E - type of elements stored in the listpublic class GapList<E>
extends java.util.AbstractList<E>
implements java.util.List<E>, java.util.RandomAccess, java.lang.Cloneable, java.io.Serializable, java.util.Deque<E>
Note that this implementation is not synchronized.
List,
ArrayList,
LinkedList,
Serialized Form| Constructor and Description |
|---|
GapList()
Construct a list with the default initial capacity.
|
GapList(java.util.Collection<? extends E> coll)
Construct a list to contain the specified elements.
|
GapList(E... elems)
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) |
boolean |
addAll(java.util.Collection<? extends E> coll)
Adds all of the elements in the specified collection into this list.
|
boolean |
addAll(E... elems)
Adds all specified elements into this list.
|
boolean |
addAll(GapList<? extends E> list)
Adds all of the elements in the specified list into this list.
|
boolean |
addAll(int index,
java.util.Collection<? extends E> coll)
Inserts all of the elements in the specified collection into this
list, starting at the specified position.
|
boolean |
addAll(int index,
E... elems)
Inserts the specified elements into this list,
starting at the specified position.
|
boolean |
addAll(int index,
GapList<? extends E> list)
Inserts all of the elements in the specified list into this
list, starting at the specified position.
|
void |
addFirst(E elem) |
void |
addLast(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.
|
<K> int |
binarySearch(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 GapList.
|
void |
clear() |
java.lang.Object |
clone()
Returns a shallow copy of this GapList instance
(The elements themselves are not copied).
|
boolean |
contains(java.lang.Object elem) |
boolean |
containsAll(java.util.Collection<?> coll) |
boolean |
containsAny(java.util.Collection<?> coll)
Returns true if any of the elements of the specified collection is contained in the list.
|
GapList<E> |
copy()
Returns a shallow copy of this GapList instance
(the new list will contain the same elements as the source list, i.e. the elements themselves are not copied).
|
static <E> void |
copy(GapList<? extends E> src,
int srcIndex,
GapList<E> dst,
int dstIndex,
int len)
Copies elements from one GapList to another.
|
void |
copy(int srcIndex,
int dstIndex,
int len)
Copy specified elements.
|
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.
|
static <E> GapList<E> |
create(int capacity)
Create new list with specified capacity.
|
java.util.Iterator<E> |
descendingIterator() |
E |
element() |
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.
|
boolean |
equals(java.lang.Object obj) |
void |
fill(E elem)
Fill list.
|
void |
fill(int index,
int len,
E elem)
Fill specified elements.
|
E |
get(int index) |
GapList<E> |
getAll(int index,
int len)
Returns specified range of elements from list.
|
E[] |
getArray(int index,
int len)
Returns specified range of elements from list.
|
E |
getFirst() |
E |
getLast() |
int |
hashCode() |
int |
indexOf(java.lang.Object elem) |
void |
init()
Initialize the list to be empty.
|
void |
init(java.util.Collection<? extends E> coll)
Initialize the list to contain the specified elements only.
|
void |
init(E... elems)
Initialize the list to contain the specified elements only.
|
void |
init(int capacity)
Initialize the list to be empty with specified initial capacity.
|
void |
init(int len,
E elem)
Initializes the list so it will afterwards have a size of
len and contain only the element elem. |
boolean |
isEmpty() |
java.util.Iterator<E> |
iterator() |
int |
lastIndexOf(java.lang.Object elem) |
java.util.ListIterator<E> |
listIterator() |
java.util.ListIterator<E> |
listIterator(int index) |
static <E> void |
move(GapList<? extends E> src,
int srcIndex,
GapList<E> dst,
int dstIndex,
int len)
Moves elements from one GapList to another.
|
void |
move(int srcIndex,
int dstIndex,
int len)
Move specified elements.
|
boolean |
offer(E elem) |
boolean |
offerFirst(E elem) |
boolean |
offerLast(E elem) |
E |
peek() |
E |
peekFirst() |
E |
peekLast() |
E |
poll() |
E |
pollFirst() |
E |
pollLast() |
E |
pop() |
void |
push(E elem) |
E |
remove() |
E |
remove(int index) |
void |
remove(int index,
int len)
Remove specified range of elements from list.
|
boolean |
remove(java.lang.Object elem) |
boolean |
removeAll(java.util.Collection<?> coll) |
boolean |
removeAll(GapList<?> coll) |
E |
removeFirst() |
boolean |
removeFirstOccurrence(java.lang.Object elem) |
E |
removeLast() |
boolean |
removeLastOccurrence(java.lang.Object elem) |
void |
resize(int len,
E elem)
Resizes the list so it will afterwards have a size of
len. |
boolean |
retainAll(java.util.Collection<?> coll) |
boolean |
retainAll(GapList<?> coll) |
void |
reverse()
Reverses the order of all elements in the specified list.
|
void |
reverse(int index,
int len)
Reverses the order of the specified elements in the list.
|
void |
rotate(int distance)
Rotate specified elements in the list.
|
void |
rotate(int index,
int len,
int distance)
Rotate specified elements in the list.
|
E |
set(int index,
E elem) |
void |
setAll(int index,
java.util.Collection<? extends E> coll)
Replaces the specified elements.
|
void |
setAll(int index,
E... elems)
Replaces the specified elements.
|
void |
setAll(int index,
GapList<? extends E> list)
Replaces the specified elements.
|
int |
size() |
void |
sort(java.util.Comparator<? super E> comparator)
Sort elements in the list using the specified comparator.
|
void |
sort(int index,
int len,
java.util.Comparator<? super E> comparator)
Sort specified elements in the list using the specified comparator.
|
static <E> void |
swap(GapList<E> src,
int srcIndex,
GapList<E> dst,
int dstIndex,
int len)
Swaps elements from two GapLists.
|
void |
swap(int index1,
int index2,
int len)
Swap the specified elements in the list.
|
java.lang.Object[] |
toArray() |
java.lang.Object[] |
toArray(int index,
int len)
Returns an array containing the specified elements in this list.
|
<T> T[] |
toArray(T[] array) |
java.lang.String |
toString() |
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.
|
public GapList()
public GapList(int capacity)
capacity - capacitypublic GapList(java.util.Collection<? extends E> coll)
coll - collection with elementspublic GapList(E... elems)
elems - array 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(int capacity)
E - type of elements stored in the listcapacity - capacitypublic static <E> GapList<E> create(java.util.Collection<? extends E> coll)
E - type of elements stored in the listcoll - collection with elementpublic static <E> GapList<E> create(E... elems)
E - type of elements stored in the listelems - array with elementspublic void init()
public void init(int capacity)
capacity - capacitypublic void init(java.util.Collection<? extends E> coll)
coll - collection with elementspublic void init(E... elems)
elems - array with elementspublic GapList<E> copy()
clone()public GapList<E> unmodifiableList()
public java.lang.Object clone()
clone in class java.lang.Objectpublic void clear()
public int size()
public int capacity()
public E get(int index)
public boolean add(E elem)
public void add(int index,
E elem)
public E remove(int index)
public void ensureCapacity(int minCapacity)
minCapacity - the desired minimum capacitypublic void trimToSize()
public boolean equals(java.lang.Object obj)
public int hashCode()
public java.lang.String toString()
toString in class java.util.AbstractCollection<E>public boolean isEmpty()
public int indexOf(java.lang.Object elem)
public int lastIndexOf(java.lang.Object elem)
public boolean remove(java.lang.Object elem)
public boolean contains(java.lang.Object elem)
public boolean containsAny(java.util.Collection<?> coll)
coll - collection with elements to be containedpublic boolean containsAll(java.util.Collection<?> coll)
public boolean removeAll(java.util.Collection<?> coll)
public boolean removeAll(GapList<?> coll)
removeAll(Collection)public boolean retainAll(java.util.Collection<?> coll)
public boolean retainAll(GapList<?> coll)
retainAll(Collection)public java.lang.Object[] toArray()
public java.lang.Object[] toArray(int index,
int len)
index - index of first element to copylen - number of elements to copypublic <T> T[] toArray(T[] array)
public boolean addAll(java.util.Collection<? extends E> coll)
addAll in interface java.util.Collection<E>addAll in interface java.util.List<E>addAll in class java.util.AbstractCollection<E>coll - collection containing elements to be added to this listjava.lang.NullPointerException - if the specified collection is nullpublic boolean addAll(int index,
java.util.Collection<? extends E> coll)
addAll in interface java.util.List<E>addAll in class java.util.AbstractList<E>index - index at which to insert the first element from the
specified collectioncoll - collection containing elements to be inserted into this listjava.lang.IndexOutOfBoundsException - if the index is invalidjava.lang.NullPointerException - if the specified collection is nullpublic boolean addAll(E... elems)
elems - elements to be added to this listpublic boolean addAll(int index,
E... elems)
index - index at which to insert the first element from the
specified collectionelems - elements to be inserted into this listjava.lang.IndexOutOfBoundsException - if the index is invalidpublic boolean addAll(GapList<? extends E> list)
list - collection containing elements to be added to this listjava.lang.NullPointerException - if the specified list is nullpublic boolean addAll(int index,
GapList<? extends E> list)
index - index at which to insert the first element from the
specified collectionlist - list containing elements to be inserted into this listjava.lang.IndexOutOfBoundsException - if the index is invalidjava.lang.NullPointerException - if the specified collection is nullpublic java.util.Iterator<E> iterator()
public java.util.ListIterator<E> listIterator()
public java.util.ListIterator<E> listIterator(int index)
public java.util.Iterator<E> descendingIterator()
descendingIterator in interface java.util.Deque<E>public E peek()
public E element()
public E poll()
public E remove()
public boolean offer(E elem)
public boolean offerFirst(E elem)
offerFirst in interface java.util.Deque<E>public boolean removeFirstOccurrence(java.lang.Object elem)
removeFirstOccurrence in interface java.util.Deque<E>public boolean removeLastOccurrence(java.lang.Object elem)
removeLastOccurrence in interface java.util.Deque<E>public static <E> void move(GapList<? extends E> src, int srcIndex, GapList<E> dst, int dstIndex, int len)
E - type of elements stored in the listsrc - source listsrcIndex - index of first element in source listdst - destination listdstIndex - index of first element in source listlen - number of elements to movejava.lang.IndexOutOfBoundsException - if the ranges are invalidpublic static <E> void copy(GapList<? extends E> src, int srcIndex, GapList<E> dst, int dstIndex, int len)
E - type of elements stored in the listsrc - source listsrcIndex - index of first element in source listdst - destination listdstIndex - index of first element in source listlen - number of elements to copyjava.lang.IndexOutOfBoundsException - if the ranges are invalidpublic static <E> void swap(GapList<E> src, int srcIndex, GapList<E> dst, int dstIndex, int len)
E - type of elements stored in the listsrc - first listsrcIndex - index of first element in first listdst - second listdstIndex - index of first element in second listlen - number of elements to swapjava.lang.IndexOutOfBoundsException - if the ranges are invalidpublic GapList<E> getAll(int index, int len)
index - index of first element to retrievelen - number of elements to retrievepublic E[] getArray(int index, int len)
index - index of first element to retrievelen - number of elements to retrievepublic void setAll(int index,
GapList<? extends E> list)
index - index of first element to setlist - list with elements to setpublic void setAll(int index,
java.util.Collection<? extends E> coll)
index - index of first element to setcoll - collection with elements to setpublic void setAll(int index,
E... elems)
index - index of first element to setelems - elements to setpublic void remove(int index,
int len)
index - index of first element to removelen - number of elements to removepublic void init(int len,
E elem)
len and contain only the element elem.
The list will grow or shrink as needed.len - length of listelem - element which the list will containpublic void resize(int len,
E elem)
len. If the list must grow, the specified
element elem will be used for filling.len - length of listelem - element which will be used for extending the listpublic void fill(E elem)
elem - element used for fillingpublic void fill(int index,
int len,
E elem)
index - index of first element to filllen - number of elements to fillelem - element used for fillingpublic void copy(int srcIndex,
int dstIndex,
int len)
srcIndex - index of first source element to copydstIndex - index of first destination element to copylen - number of elements to copypublic void move(int srcIndex,
int dstIndex,
int len)
srcIndex - index of first source element to movedstIndex - index of first destination element to movelen - number of elements to movepublic void reverse()
public void reverse(int index,
int len)
index - index of first element to reverselen - number of elements to reversepublic void swap(int index1,
int index2,
int len)
index1 - index of first element in first range to swapindex2 - index of first element in second range to swaplen - number of elements to swapjava.lang.IndexOutOfBoundsException - if the ranges overlappublic void rotate(int distance)
distance - distance to move the elementspublic void rotate(int index,
int len,
int distance)
index - index of first element to rotatelen - number of elements to rotatedistance - distance to move the elementspublic void sort(java.util.Comparator<? super E> comparator)
comparator - comparator to use for sorting
(null means the elements natural ordering should be used)Arrays.sort(int[])public void sort(int index,
int len,
java.util.Comparator<? super E> comparator)
index - index of first element to sortlen - number of elements to sortcomparator - comparator to use for sorting
(null means the elements natural ordering should be used)Arrays.sort(int[])public <K> int binarySearch(K key,
java.util.Comparator<? super K> comparator)
key - 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)public <K> int binarySearch(int index,
int len,
K key,
java.util.Comparator<? super K> comparator)
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)