|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractCollection java.util.AbstractList com.virtuosotechnologies.lib.ring.RotatingArrayList
Rotating resizeable array implementation of the List interface. Implements all optional list operations, and permits all elements, including null. In addition to implementing the List interface, this class provides methods to manipulate the size of the array that is used internally to store the list.
This class is roughly equivalent to ArrayList (and is based on the ArrayList implementation) with one important distinction. The add(index, object) method operates in amortized constant time rather than linear time when inserting at the beginning or end of a list, and the remove(index) method also operates in amortized constant time when removing from the beginning or end. This enables efficient use of this class in double-ended queues.
This class is not thread-safe.
Field Summary |
Fields inherited from class java.util.AbstractList |
modCount |
Constructor Summary | |
RotatingArrayList()
Constructs an empty list. |
|
RotatingArrayList(Collection c)
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator. |
|
RotatingArrayList(int initialCapacity)
Constructs an empty list with the specified initial capacity. |
Method Summary | |
void |
add(int index,
Object element)
Inserts the specified element at the specified position in this list. |
boolean |
add(Object o)
Appends the specified element to the end of this list. |
boolean |
addAll(Collection 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(int index,
Collection c)
Inserts all of the elements in the specified Collection into this list, starting at the specified position. |
boolean |
addAllFirst(Collection c)
Appends all of the elements in the specified Collection to the beginning of this list, in the order that they are returned by the specified Collection's Iterator. |
boolean |
addAllLast(Collection 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 |
addFirst(Object o)
Appends the specified element to the front of this list. |
boolean |
addLast(Object o)
Appends the specified element to the back of this list. |
void |
clear()
Removes all of the elements from this list. |
Object |
clone()
Returns a shallow copy of this RotatingArrayList instance. |
boolean |
contains(Object elem)
Returns true if this list contains the specified element. |
void |
ensureCapacity(int minCapacity)
Increases the capacity of this ArraRotatingArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument. |
Object |
get(int index)
Returns the element at the specified position in this list. |
Object |
getFirst()
Returns the element at the front of the list. |
Object |
getLast()
Returns the element at the back of the 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. |
Object |
remove(int index)
Removes the element at the specified position in this list. |
Object |
removeFirst()
Removes the element from the front of this list. |
void |
removeFirst(int num)
Removes from this List the first num elements. |
Object |
removeLast()
Removes the element from the back of this list. |
void |
removeLast(int num)
Removes from this List the last num elements. |
void |
removeRange(int fromIndex,
int toIndex)
Removes from this List all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive. |
Object |
set(int index,
Object element)
Replaces the element at the specified position in this list with the specified element. |
Object |
setFirst(Object element)
Replaces the element at the front of this list with the specified element. |
Object |
setLast(Object element)
Replaces the element at the back of this list with the specified element. |
int |
size()
Returns the number of elements in this list. |
Object[] |
toArray()
Returns an array containing all of the elements in this list in the correct order. |
Object[] |
toArray(Object[] a)
Returns an array containing all of the elements in this list in the correct order. |
void |
trimToSize()
Trims the capacity of this RotatingArrayList instance to be the list's current size. |
Methods inherited from class java.util.AbstractList |
equals, hashCode, iterator, listIterator, listIterator, subList |
Methods inherited from class java.util.AbstractCollection |
containsAll, remove, removeAll, retainAll, toString |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList |
Constructor Detail |
public RotatingArrayList(int initialCapacity)
initialCapacity
- the initial capacity of the list.
IllegalArgumentException
- if the specified initial capacity
is negativepublic RotatingArrayList()
public RotatingArrayList(Collection c)
c
- the collection whose elements are to be placed into this list.Method Detail |
public void trimToSize()
public void ensureCapacity(int minCapacity)
minCapacity
- the desired minimum capacity.public int size()
size
in interface List
public boolean isEmpty()
isEmpty
in interface List
public boolean contains(Object elem)
contains
in interface List
elem
- element whose presence in this List is to be tested.public int indexOf(Object elem)
indexOf
in interface List
elem
- an object.
public int lastIndexOf(Object elem)
lastIndexOf
in interface List
elem
- the desired element.
public Object clone()
public Object[] toArray()
toArray
in interface List
public Object[] toArray(Object[] 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 List
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 Object get(int index)
get
in interface List
index
- index of element to return.
IndexOutOfBoundsException
- if index is out of range (index
< 0 || index >= size()).public Object getFirst()
IndexOutOfBoundsException
- if the list is emptypublic Object getLast()
IndexOutOfBoundsException
- if the list is emptypublic Object set(int index, Object element)
set
in interface List
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 Object setFirst(Object element)
element
- element to be stored at the front.
IndexOutOfBoundsException
- if the list is empty.public Object setLast(Object element)
element
- element to be stored at the back.
IndexOutOfBoundsException
- if the list is empty.public boolean add(Object o)
add
in interface List
o
- element to be appended to this list.
public boolean addLast(Object o)
o
- element to be appended to this list.
public boolean addFirst(Object o)
o
- element to be appended to this list.
public void add(int index, Object element)
add
in interface List
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 Object removeFirst()
IndexOutOfBoundsException
- if the list is empty.public Object removeLast()
IndexOutOfBoundsException
- if the list is empty.public Object remove(int index)
remove
in interface List
index
- the index of the element to removed.
IndexOutOfBoundsException
- if index out of range (index
< 0 || index >= size()).public void clear()
clear
in interface List
public boolean addAll(Collection c)
addAll
in interface List
c
- the elements to be inserted into this list.
IndexOutOfBoundsException
- if index out of range (index
< 0 || index > size()).public boolean addAllLast(Collection c)
c
- the elements to be inserted into this list.
IndexOutOfBoundsException
- if index out of range (index
< 0 || index > size()).public boolean addAllFirst(Collection c)
c
- the elements to be inserted into this list.
IndexOutOfBoundsException
- if index out of range (index
< 0 || index > size()).public boolean addAll(int index, Collection c)
addAll
in interface List
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()).public void removeLast(int num)
num
- number of elements to removepublic void removeFirst(int num)
num
- number of elements to removepublic void removeRange(int fromIndex, int toIndex)
AbstractList.removeRange() is protected, but RotatingArrayList makes this method public since it may be useful to clients.
fromIndex
- index of first element to be removed.toIndex
- index after last element to be removed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |