public class ObjectArrayList<T> extends AbstractObjectList<T>
${valueType}
elements; implemented with arrays.Constructor and Description |
---|
ObjectArrayList()
Constructs an empty list.
|
ObjectArrayList(int initialCapacity)
Constructs an empty list with the specified initial capacity.
|
ObjectArrayList(T[] elements)
Constructs a list containing the specified elements.
|
Modifier and Type | Method and Description |
---|---|
void |
add(T element)
Appends the specified element to the end of this list.
|
void |
beforeInsert(int index,
T element)
Inserts the specified element before the specified position into the receiver.
|
protected void |
beforeInsertDummies(int index,
int length)
Inserts length dummy elements before the specified position into the receiver.
|
Object |
clone()
Returns a deep copy of the receiver.
|
ObjectArrayList<T> |
copy()
Returns a deep copy of the receiver; uses
clone() and casts the result. |
<Q> Q[] |
elements()
Returns the elements currently stored, including invalid elements between size and capacity, if any.
|
void |
elements(T[] elements)
Sets the receiver's elements to be the specified array (not a copy of it).
|
void |
ensureCapacity(int minCapacity)
Ensures that the receiver can hold at least the specified number of elements without needing to allocate new
internal memory.
|
boolean |
equals(Object otherObj)
Compares the specified Object with the receiver.
|
boolean |
forEach(ObjectProcedure<T> procedure)
Applies a procedure to each element of the receiver, if any.
|
T |
get(int index)
Returns the element at the specified position in the receiver.
|
T |
getQuick(int index)
Returns the element at the specified position in the receiver; WARNING: Does not check preconditions.
|
int |
indexOfFromTo(T element,
int from,
int to)
Returns the index of the first occurrence of the specified element.
|
int |
lastIndexOfFromTo(T element,
int from,
int to)
Returns the index of the last occurrence of the specified element.
|
void |
mergeSortFromTo(int from,
int to)
Sorts the receiver into ascending order.
|
AbstractObjectList<T> |
partFromTo(int from,
int to)
Returns a new list of the part of the receiver between
from , inclusive, and to ,
inclusive. |
void |
quickSortFromTo(int from,
int to)
Sorts the specified range of the receiver into ascending order.
|
void |
removeFromTo(int fromIndex,
int toIndex)
Removes from the receiver all elements whose index is between
from , inclusive and to ,
inclusive. |
void |
replaceFromWith(int from,
Collection<T> other)
Replaces the part of the receiver starting at
from (inclusive) with all the elements of the specified
collection. |
void |
reverse()
Reverses the elements of the receiver.
|
void |
set(int index,
T element)
Replaces the element at the specified position in the receiver with the specified element.
|
void |
setQuick(int index,
T element)
Replaces the element at the specified position in the receiver with the specified element; WARNING: Does not
check preconditions.
|
int |
size() |
void |
trimToSize()
Trims the capacity of the receiver to be the receiver's current size.
|
addAllOf, beforeInsertAllOf
checkRange, checkRangeFromTo, clear, isEmpty, mergeSort, quickSort, remove, setSize, sort, sortFromTo
public ObjectArrayList()
public ObjectArrayList(T[] elements)
elements
- the array to be backed by the the constructed listpublic ObjectArrayList(int initialCapacity)
initialCapacity
- the number of elements the receiver can hold without auto-expanding itself by allocating new
internal memory.public void add(T element)
element
- element to be appended to this list.public void beforeInsert(int index, T element)
index
- index before which the specified element is to be inserted (must be in [0,size]).element
- element to be inserted.IndexOutOfBoundsException
- index is out of range (index < 0 || index > size()).public Object clone()
clone
in class PersistentObject
public ObjectArrayList<T> copy()
clone()
and casts the result.public <Q> Q[] elements()
public void elements(T[] elements)
elements
- the new elements to be stored.public void ensureCapacity(int minCapacity)
minCapacity
- the desired minimum capacity.public boolean equals(Object otherObj)
public boolean forEach(ObjectProcedure<T> procedure)
procedure
- the procedure to be applied. Stops iteration if the procedure returns false, otherwise
continues.public T get(int index)
index
- index of element to return.IndexOutOfBoundsException
- index is out of range (index < 0 || index >= size()).public T getQuick(int index)
index
- index of element to return.public int indexOfFromTo(T element, int from, int to)
-1
if the receiver does
not contain this element. Searches between from
, inclusive and to
, inclusive. Tests for
identity.element
- element to search for.from
- the leftmost search position, inclusive.to
- the rightmost search position, inclusive.-1
if the element is
not found.IndexOutOfBoundsException
- index is out of range (size()>0 && (from<0 || from>to ||
to>=size())).public int lastIndexOfFromTo(T element, int from, int to)
-1
if the receiver does not
contain this element. Searches beginning at to
, inclusive until from
, inclusive. Tests
for identity.element
- element to search for.from
- the leftmost search position, inclusive.to
- the rightmost search position, inclusive.-1
if the element is
not found.IndexOutOfBoundsException
- index is out of range (size()>0 && (from<0 || from>to ||
to>=size())).public AbstractObjectList<T> partFromTo(int from, int to)
from
, inclusive, and to
,
inclusive.from
- the index of the first element (inclusive).to
- the index of the last element (inclusive).IndexOutOfBoundsException
- index is out of range (size()>0 && (from<0 || from>to ||
to>=size())).public void reverse()
reverse
in class AbstractList
public void set(int index, T element)
index
- index of element to replace.element
- element to be stored at the specified position.IndexOutOfBoundsException
- index is out of range (index < 0 || index >= size()).public void setQuick(int index, T element)
index >= 0 && index < size()
.index
- index of element to replace.element
- element to be stored at the specified position.public void trimToSize()
trimToSize
in class AbstractList
public void removeFromTo(int fromIndex, int toIndex)
AbstractList
from
, inclusive and to
,
inclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by
(to - from + 1) elements.removeFromTo
in class AbstractList
fromIndex
- index of first element to be removed.toIndex
- index of last element to be removed.public void replaceFromWith(int from, Collection<T> other)
AbstractObjectList
from
(inclusive) with all the elements of the specified
collection. Does not alter the size of the receiver. Replaces exactly Math.max(0,Math.min(size()-from,
other.size())) elements.replaceFromWith
in class AbstractObjectList<T>
from
- the index at which to copy the first element from the specified collection.other
- Collection to replace part of the receiverprotected void beforeInsertDummies(int index, int length)
AbstractList
beforeInsertDummies
in class AbstractList
index
- index before which to insert dummy elements (must be in [0,size])..length
- number of dummy elements to be inserted.public void mergeSortFromTo(int from, int to)
AbstractList
The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n*log(n) performance, and can approach linear performance on nearly sorted lists.
You should never call this method unless you are sure that this particular sorting algorithm is the right one for your data set. It is generally better to call sort() or sortFromTo(...) instead, because those methods automatically choose the best sorting algorithm.
mergeSortFromTo
in class AbstractList
from
- the index of the first element (inclusive) to be sorted.to
- the index of the last element (inclusive) to be sorted.public void quickSortFromTo(int from, int to)
AbstractList
You should never call this method unless you are sure that this particular sorting algorithm is the right one for your data set. It is generally better to call sort() or sortFromTo(...) instead, because those methods automatically choose the best sorting algorithm.
quickSortFromTo
in class AbstractList
from
- the index of the first element (inclusive) to be sorted.to
- the index of the last element (inclusive) to be sorted.public int size()
size
in class AbstractList
Copyright © 2008–2017 The Apache Software Foundation. All rights reserved.