public class GapList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, Serializable
modCount
Constructor and Description |
---|
GapList()
Constructs an empty list with an initial capacity of ten.
|
GapList(Collection<? extends E> c)
Constructs a list containing the elements of the specified
collection, in the order they are returned by the collection's
iterator.
|
GapList(int initialCapacity)
Constructs an empty list with the specified initial capacity.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E element)
Appends the specified element to the end of this list.
|
void |
add(int index,
E element)
Inserts the specified element at the specified position in this
list.
|
boolean |
addAll(Collection<? extends E> c)
Appends all of the elements in the specified Collection to the end of
this list, in the order that they are returned by the
specified Collection's Iterator.
|
boolean |
addAll(Collection<? extends E> c,
int off,
int len)
Appends elements from the specified collection to the end of
this list, in the order that they are returned by the
specified collection's iterator.
|
boolean |
addAll(int index,
Collection<? extends E> c)
Inserts all of the elements in the specified Collection into this
list, starting at the specified position.
|
boolean |
addAll(int index,
Collection<? extends E> c,
int off,
int len)
Inserts elements in the specified Collection into this
list, starting at the specified position.
|
boolean |
addArray(int index,
Object[] elements)
Inserts all elements from the given array into this list, starting
at the given index.
|
boolean |
addArray(int index,
Object[] elements,
int off,
int len)
Inserts elements from the given array into this list, starting
at the given index.
|
boolean |
addArray(Object[] elements)
Inserts all elements of the given array at the end of this list.
|
void |
clear()
Removes all of the elements from this list.
|
Object |
clone()
Returns a shallow copy of this GapList instance.
|
protected void |
consistencyCheck()
Internal consistency check.
|
protected void |
consistencyError(String s) |
boolean |
contains(Object elem)
Returns true if this list contains the specified element.
|
GapList<E> |
copy()
Create shallow copy of this gap list.
|
void |
copyElements(int startIndex,
int endIndex,
Collection<E> dest)
Copy elements of this list between the given index range
to the end of the given collection.
|
void |
copyElements(int startIndex,
int endIndex,
Object[] dest,
int destIndex)
Copy elements of this list between the given index range to the given object array.
|
void |
copyItems(int startIndex,
int endIndex,
Object[] dest,
int destIndex)
Deprecated.
use
GapList.copyElements(int, int, Object[], int) which performs the same operation |
protected String |
dumpDetails() |
static String |
dumpElements(List l) |
protected String |
dumpInternals() |
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)
Returns the element at the specified position in this list.
|
int |
indexOf(Object elem)
Searches for the first occurence of the given argument, testing
for equality using the equals method.
|
boolean |
isEmpty()
Tests if this list has no elements.
|
int |
lastIndexOf(Object elem)
Returns the index of the last occurrence of the specified object in
this list.
|
E |
remove(int index)
Removes the element at the specified position in this list.
|
void |
remove(int index,
int count)
Removes elements at the given index.
|
protected void |
removeRange(int fromIndex,
int toIndex)
Removes from this List all of the elements whose index is between
fromIndex, inclusive and toIndex, exclusive.
|
E |
set(int index,
E element)
Replaces the element at the specified position in this list with
the specified element.
|
int |
size()
Returns the number of elements in this list.
|
void |
swap(int index1,
int index2)
Swap elements at the given indexes.
|
Object[] |
toArray()
Returns an array containing all of the elements in this list
in the correct order.
|
<T> T[] |
toArray(T[] a)
Returns an array containing all of the elements in this list in the
correct order; the runtime type of the returned array is that of the
specified array.
|
String |
toString() |
void |
trimToSize()
Trims the capacity of this GapList instance to be the
list's current size.
|
equals, hashCode, iterator, listIterator, listIterator, subList
containsAll, remove, removeAll, retainAll
finalize, getClass, notify, notifyAll, wait, wait, wait
addFirst, addLast, containsAll, copyOf, equals, getFirst, getLast, hashCode, iterator, listIterator, listIterator, of, of, of, of, of, of, of, of, of, of, of, of, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, subList
parallelStream, removeIf, stream, toArray
public GapList(int initialCapacity)
initialCapacity
- the initial capacity of the list.IllegalArgumentException
- if the specified initial capacity
is negativepublic GapList()
public GapList(Collection<? extends E> c)
c
- the collection whose elements are to be placed into this list.NullPointerException
- if the specified collection is null.public void trimToSize()
public void ensureCapacity(int minCapacity)
minCapacity
- the desired minimum capacity.public int size()
size
in interface Collection<E>
size
in interface List<E>
size
in class AbstractCollection<E>
public boolean isEmpty()
isEmpty
in interface Collection<E>
isEmpty
in interface List<E>
isEmpty
in class AbstractCollection<E>
public boolean contains(Object elem)
contains
in interface Collection<E>
contains
in interface List<E>
contains
in class AbstractCollection<E>
elem
- element whose presence in this List is to be tested.true
if the specified element is present;
false
otherwise.public int indexOf(Object elem)
indexOf
in interface List<E>
indexOf
in class AbstractList<E>
elem
- an object.Object.equals(Object)
public int lastIndexOf(Object elem)
lastIndexOf
in interface List<E>
lastIndexOf
in class AbstractList<E>
elem
- the desired element.public Object clone()
public GapList<E> copy()
@Deprecated public void copyItems(int startIndex, int endIndex, Object[] dest, int destIndex)
GapList.copyElements(int, int, Object[], int)
which performs the same operationpublic void copyElements(int startIndex, int endIndex, Object[] dest, int destIndex)
startIndex
- start index of the region of this list to be copied.endIndex
- end index of the region of this list to be copied.dest
- collection to the end of which the items should be copied.public void copyElements(int startIndex, int endIndex, Collection<E> dest)
startIndex
- start index of the region of this list to be copied.endIndex
- end index of the region of this list to be copied.dest
- collection to the end of which the items should be copied.public Object[] toArray()
toArray
in interface Collection<E>
toArray
in interface List<E>
toArray
in class AbstractCollection<E>
public <T> T[] toArray(T[] a)
If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.
toArray
in interface Collection<E>
toArray
in interface List<E>
toArray
in class AbstractCollection<E>
a
- the array into which the elements of the list are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.ArrayStoreException
- if the runtime type of a is not a supertype
of the runtime type of every element in this list.public E get(int index)
get
in interface List<E>
get
in class AbstractList<E>
index
- index of element to return.IndexOutOfBoundsException
- if index is out of range (index
< 0 || index >= size()).public E set(int index, E element)
set
in interface List<E>
set
in class AbstractList<E>
index
- index of element to replace.element
- element to be stored at the specified position.IndexOutOfBoundsException
- if index out of range
(index < 0 || index >= size()).public void swap(int index1, int index2)
public boolean add(E element)
add
in interface Collection<E>
add
in interface List<E>
add
in class AbstractList<E>
element
- non-null element to be appended to this list.public void add(int index, E element)
add
in interface List<E>
add
in class AbstractList<E>
index
- index at which the specified element is to be inserted.element
- element to be inserted.IndexOutOfBoundsException
- if index is out of range
(index < 0 || index > size()).public boolean addAll(Collection<? extends E> c)
addAll
in interface Collection<E>
addAll
in interface List<E>
addAll
in class AbstractCollection<E>
c
- the elements to be inserted into this list.NullPointerException
- if the specified collection is null.public boolean addAll(Collection<? extends E> c, int off, int len)
c
- collection containing the elements to be inserted into this list.off
- offset in the collection pointing to first element to copy.len
- number of elements to copy from the collection.NullPointerException
- if the specified Collection is null.public boolean addAll(int index, Collection<? extends E> c)
addAll
in interface List<E>
addAll
in class AbstractList<E>
index
- index at which to insert first element
from the specified collection.c
- elements to be inserted into this list.IndexOutOfBoundsException
- if index out of range (index
< 0 || index > size()).NullPointerException
- if the specified Collection is null.public boolean addAll(int index, Collection<? extends E> c, int off, int len)
index
- index at which to insert first element
from the specified collection.c
- collection containing the elements to be inserted into this list.off
- offset in the collection pointing to first element to copy.len
- number of elements to copy from the collection.IndexOutOfBoundsException
- if index out of range (index
< 0 || index > size()).NullPointerException
- if the specified Collection is null.public boolean addArray(Object[] elements)
elements
- array of elements to insert.public boolean addArray(int index, Object[] elements)
index
- index at which to insert first element from the array.elements
- array of elements to insert.public boolean addArray(int index, Object[] elements, int off, int len)
index
- index at which to insert first element.elements
- array of elements from which to insert elements.off
- offset in the elements pointing to first element to copy.len
- number of elements to copy from the elements array.public void clear()
clear
in interface Collection<E>
clear
in interface List<E>
clear
in class AbstractList<E>
public E remove(int index)
remove
in interface List<E>
remove
in class AbstractList<E>
index
- the index of the element to removed.IndexOutOfBoundsException
- if index out of range (index
< 0 || index >= size()).public void remove(int index, int count)
index
- index of the first element to be removed.count
- number of elements to remove.protected void removeRange(int fromIndex, int toIndex)
removeRange
in class AbstractList<E>
fromIndex
- index of first element to be removed.toIndex
- index after last element to be removed.protected void consistencyCheck()
protected final void consistencyError(String s)
protected String dumpDetails()
protected String dumpInternals()
public String toString()
toString
in class AbstractCollection<E>