|
Oracle® Coherence Java API Reference Release 3.6.0.0 E15725-01 |
|||||||
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.tangosol.util.CircularArrayList
public class CircularArrayList
Resizable-array implementation of the List interface. Implements all optional list operations, and permits all elements, including null. (This class is roughly equivalent to ArrayList, except that it is optimized for removing elements at the front and back of the list to facilitate use as a queue or deque.
The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation.
Each CircularArrayList instance has a capacity. The capacity is the size of the array used to store the elements in the list. It is always at least as large as the list size. As elements are added to an CircularArrayList, its capacity grows automatically. The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.
An application can increase the capacity of an CircularArrayList instance before adding a large number of elements using the ensureCapacity operation. This may reduce the amount of incremental reallocation.
Note that this implementation is not synchronized. If multiple threads access a CircularArrayList concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements, or explicitly resizes the backing array; merely setting the value of an element is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the list. If no object exists, the list should be "wrapped" using the Collections.synchronizedList method. This is best done at creation time, to prevent accidental unsynchronized access to the list:
List list = Collections.synchronizedList(new CircularArrayList(...));
The iterators returned by this class's iterator and listIterator methods are fail-fast: if list is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.
Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: the fail-fast behavior of iterators should be used only to detect bugs.
Field Summary | |
---|---|
protected Object[] |
m_aoData The array into which the elements of the list are stored. |
protected int |
m_cElements The size of the list (the number of elements it contains). |
protected int |
m_iFirst The offset to the first element. |
protected int |
m_iLast The offset to one past the last element. |
Fields inherited from class java.util.AbstractList |
---|
modCount |
Constructor Summary | |
---|---|
CircularArrayList() Create a new CircularArrayList with default settings. |
|
CircularArrayList(Collection c) Construct a CircularArrayList containing the elements of the specified collection in the order they are returned by the collection's iterator. |
|
CircularArrayList(int cInitialElements) Create a new CircularArrayList with the specified initial capacity. |
Method Summary | |
---|---|
void |
add(int index, Object o) Insert the element at the specified position in this list. |
boolean |
add(Object o) Appends the specified element to the end of this List (optional operation). |
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. |
void |
clear() Removes all of the elements from this collection (optional operation). |
Object |
clone() Returns a shallow copy of this list instance. |
boolean |
contains(Object o) Returns true if this collection contains the specified element. |
void |
dump() Outputs information to standard output about representation for debugging purposes. |
protected int |
effectiveIndex(int index) Calculate the effective index taking into account offsets and the circular nature of CircularArrayList. |
boolean |
ensureCapacity(int cMin) Increase the capacity of this list instance, if necessary, to ensure that it can hold at least the specified number of elements. |
protected boolean |
ensureCompactness() Ensure the representation of this list is appropriatly compact by shrinking if necessary. |
protected int |
ensureEffectiveIndex(int index) After range checking Calculate the effective index while taking into account the offsets and the circular nature of the list. |
Object |
get(int index) Returns the element at the specified position in this list. |
int |
indexOf(Object o) Search for the first occurence of the given argument, testing for equality using the equals method. |
boolean |
isEmpty() Returns true if this collection contains no elements. |
int |
lastIndexOf(Object o) Returns the index of the last occurrence of the specified object in this CycicArrayList. |
protected void |
rangeCheck(int index) Check if the given index is in range. |
Object |
remove(int index) Removes the element at the specified position in this list. |
protected void |
removeRange(int fromIndex, int toIndex) Removes from this list all of the elements whose indexes are between fromIndex, inclusive and toIndex, exclusive. |
Object |
set(int index, Object o) Replaces the element at the specified position in this list with the specified element (optional operation). |
int |
size() Returns the number of elements in this collection. |
Object[] |
toArray() Returns an array containing all of the elements in this collection. |
Object[] |
toArray(Object[] ao) Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. |
void |
trimToSize() Trim the capacity of this list instance to be as small as possible. |
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 interface java.util.List |
---|
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList |
Field Detail |
---|
protected Object[] m_aoData
protected int m_iFirst
protected int m_iLast
protected int m_cElements
Constructor Detail |
---|
public CircularArrayList()
public CircularArrayList(int cInitialElements)
cInitialElements
- the initial capacity of the listIllegalArgumentException
- if the specified initial capacity is negativepublic CircularArrayList(Collection c)
c
- the collection whose elements are to be placed into this listMethod Detail |
---|
public void trimToSize()
public boolean ensureCapacity(int cMin)
cMin
- the minimum allowable capacitypublic int size()
size
in interface Collection
size
in interface List
size
in class AbstractCollection
public boolean isEmpty()
This implementation returns size() == 0.
isEmpty
in interface Collection
isEmpty
in interface List
isEmpty
in class AbstractCollection
public boolean contains(Object o)
This implementation iterates over the elements in the collection, checking each element in turn for equality with the specified element.
contains
in interface Collection
contains
in interface List
contains
in class AbstractCollection
o
- object to be checked for containment in this collection.public int indexOf(Object o)
indexOf
in interface List
indexOf
in class AbstractList
o
- the element to search forpublic int lastIndexOf(Object o)
lastIndexOf
in interface List
lastIndexOf
in class AbstractList
o
- the element to search forpublic Object[] toArray()
This implementation allocates the array to be returned, and iterates over the elements in the collection, storing each object reference in the next consecutive element of the array, starting with element 0.
toArray
in interface Collection
toArray
in interface List
toArray
in class AbstractCollection
Arrays.asList(Object[])
public Object[] toArray(Object[] ao)
If the collection fits in the specified array with room to spare (i.e., the array has more elements than the collection), 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 collection only if the caller knows that the collection does not contain any null elements.)
If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
This implementation checks if the array is large enough to contain the collection; if not, it allocates a new array of the correct size and type (using reflection). Then, it iterates over the collection, storing each object reference in the next consecutive element of the array, starting with element 0. If the array is larger than the collection, a null is stored in the first location after the end of the collection.
toArray
in interface Collection
toArray
in interface List
toArray
in class AbstractCollection
ao
- the array into which the elements of the collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.public Object get(int index)
get
in interface List
get
in class AbstractList
index
- index of element to return.public Object set(int index, Object o)
This implementation always throws an UnsupportedOperationException.
set
in interface List
set
in class AbstractList
index
- index of element to replace.o
- element to be stored at the specified position.public boolean add(Object o)
This implementation calls add(size(), o).
Note that this implementation throws an UnsupportedOperationException unless add(int, Object) is overridden.
add
in interface Collection
add
in interface List
add
in class AbstractList
o
- element to be appended to this list.public void add(int index, Object o)
add
in interface List
add
in class AbstractList
index
- the index at which the specified element will be insertedo
- the element to be insertedIndexOutOfBoundsException
- if index is out of rangepublic Object remove(int index)
remove
in interface List
remove
in class AbstractList
index
- the index of the element to removedIndexOutOfBoundsException
- if index out of rangepublic void clear()
This implementation calls removeRange(0, size()).
Note that this implementation throws an UnsupportedOperationException unless remove(int index) or removeRange(int fromIndex, int toIndex) is overridden.
clear
in interface Collection
clear
in interface List
clear
in class AbstractList
public boolean addAll(Collection c)
addAll
in interface Collection
addAll
in interface List
addAll
in class AbstractCollection
c
- the elements to be inserted into this listNullPointerException
- if the specified collection is null.AbstractCollection.add(Object)
public boolean addAll(int index, Collection c)
addAll
in interface List
addAll
in class AbstractList
index
- the index at which to insert first element from the specified collectionc
- the elements to be inserted into this listIndexOutOfBoundsException
- if index out of rangeNullPointerException
- if the specified Collection is nullprotected void removeRange(int fromIndex, int toIndex)
removeRange
in class AbstractList
fromIndex
- the index of first element to be removedtoIndex
- the index after last element to be removed.public Object clone()
protected int effectiveIndex(int index)
index
- the index to transformprotected void rangeCheck(int index)
index
- the index to be checked for being between size() and 0 inclusiveIndexOutOfBoundsException
protected int ensureEffectiveIndex(int index)
index
- the index to transformIndexOutOfBoundsException
protected boolean ensureCompactness()
public void dump()
|
Oracle® Coherence Java API Reference Release 3.6.0.0 E15725-01 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |