Overview | Package | Class | Tree | Index | Help

Oracle® Coherence Java API Reference
v3.5.3
E15583-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.tangosol.util
Class CircularArrayList

    java.lang.Object
      java.util.AbstractCollection
          java.util.AbstractList
              com.tangosol.util.CircularArrayList

All Implemented Interfaces:
  java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess

    public class CircularArrayList

extends java.util.AbstractList
implements java.util.List, java.util.RandomAccess, java.lang.Cloneable, java.io.Serializable

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.

Since:
  Coherence 3.5
Author:
  djl 2008.10.22

Field Summary
`protected java.lang.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(java.util.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, java.lang.Object o)` Insert the element at the specified position in this list.
`boolean` | `add(java.lang.Object o)`
`boolean` | `addAll(java.util.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, java.util.Collection c)` Inserts all of the elements in the specified Collection into this list, starting at the specified position.
`void` | `clear()`
`java.lang.Object` | `clone()` Returns a shallow copy of this list instance.
`boolean` | `contains(java.lang.Object o)`
`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.
`java.lang.Object` | `get(int index)`
`int` | `indexOf(java.lang.Object o)` Search for the first occurence of the given argument, testing for equality using the equals method.
`boolean` | `isEmpty()`
`int` | `lastIndexOf(java.lang.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.
`java.lang.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.
`java.lang.Object` | `set(int index, java.lang.Object o)`
`int` | `size()`
`java.lang.Object[]` | `toArray()`
`java.lang.Object[]` | `toArray(java.lang.Object[] ao)`
`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

### m_aoData

    protected java.lang.Object[] m_aoData

  The array into which the elements of the list are stored. The capacity of the list is the length of this array buffer.

### m_iFirst

    protected int m_iFirst

  The offset to the first element.

### m_iLast

    protected int m_iLast

  The offset to one past the last element.

### m_cElements

    protected int m_cElements

  The size of the list (the number of elements it contains).

Constructor Detail

### CircularArrayList

    public CircularArrayList()

  Create a new CircularArrayList with default settings.

### CircularArrayList

    public CircularArrayList(int cInitialElements)

  Create a new CircularArrayList with the specified initial capacity.

  Parameters:
    `cInitialElements` - the initial capacity of the list
  Throws:
    `java.lang.IllegalArgumentException` - if the specified initial capacity is negative

### CircularArrayList

    public CircularArrayList(java.util.Collection c)

  Construct a CircularArrayList containing the elements of the specified collection in the order they are returned by the collection's iterator.

  Parameters:
    `c` - the collection whose elements are to be placed into this list

Method Detail

### trimToSize

    public void trimToSize()

  Trim the capacity of this list instance to be as small as possible.

### ensureCapacity

    public 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.

  Parameters:
    `cMin` - the minimum allowable capacity
  Returns:
    true if the capacity was increased

### size

    public int size()

  Specified by:
    `size` in interface `java.util.Collection`
  Specified by:
    `size` in interface `java.util.List`
  Specified by:
    `size` in class `java.util.AbstractCollection`

### isEmpty

    public boolean isEmpty()

  Specified by:
    `isEmpty` in interface `java.util.Collection`
  Specified by:
    `isEmpty` in interface `java.util.List`
  Overrides:
    `isEmpty` in class `java.util.AbstractCollection`

### contains

    public boolean contains(java.lang.Object o)

  Specified by:
    `contains` in interface `java.util.Collection`
  Specified by:
    `contains` in interface `java.util.List`
  Overrides:
    `contains` in class `java.util.AbstractCollection`

### indexOf

    public int indexOf(java.lang.Object o)

  Search for the first occurence of the given argument, testing for equality using the equals method.

  Specified by:
    `indexOf` in interface `java.util.List`
  Overrides:
    `indexOf` in class `java.util.AbstractList`
  Parameters:
    `o` - the element to search for
  Returns:
    the index of the first occurrence of the argument in this list; returns -1 if the object is not found

### lastIndexOf

    public int lastIndexOf(java.lang.Object o)

  Returns the index of the last occurrence of the specified object in this CycicArrayList.

  Specified by:
    `lastIndexOf` in interface `java.util.List`
  Overrides:
    `lastIndexOf` in class `java.util.AbstractList`
  Parameters:
    `o` - the element to search for
  Returns:
    the index of the last occurrence of the specified object in this list; returns -1 if the object is not found

### toArray

    public java.lang.Object[] toArray()

  Specified by:
    `toArray` in interface `java.util.Collection`
  Specified by:
    `toArray` in interface `java.util.List`
  Overrides:
    `toArray` in class `java.util.AbstractCollection`

### toArray

    public java.lang.Object[] toArray(java.lang.Object[] ao)

  Specified by:
    `toArray` in interface `java.util.Collection`
  Specified by:
    `toArray` in interface `java.util.List`
  Overrides:
    `toArray` in class `java.util.AbstractCollection`

### get

    public java.lang.Object get(int index)

  Specified by:
    `get` in interface `java.util.List`
  Specified by:
    `get` in class `java.util.AbstractList`

### set

    public java.lang.Object set(int index,
                                java.lang.Object o)

  Specified by:
    `set` in interface `java.util.List`
  Overrides:
    `set` in class `java.util.AbstractList`

### add

    public boolean add(java.lang.Object o)

  Specified by:
    `add` in interface `java.util.Collection`
  Specified by:
    `add` in interface `java.util.List`
  Overrides:
    `add` in class `java.util.AbstractList`

### add

    public void add(int index,
                    java.lang.Object o)

  Insert the element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

  Specified by:
    `add` in interface `java.util.List`
  Overrides:
    `add` in class `java.util.AbstractList`
  Parameters:
    `index` - the index at which the specified element will be inserted
    `o` - the element to be inserted
  Throws:
    `java.lang.IndexOutOfBoundsException` - if index is out of range

### remove

    public java.lang.Object remove(int index)

  Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).

  Specified by:
    `remove` in interface `java.util.List`
  Overrides:
    `remove` in class `java.util.AbstractList`
  Parameters:
    `index` - the index of the element to removed
  Returns:
    the element that was removed from the list
  Throws:
    `java.lang.IndexOutOfBoundsException` - if index out of range

### clear

    public void clear()

  Specified by:
    `clear` in interface `java.util.Collection`
  Specified by:
    `clear` in interface `java.util.List`
  Overrides:
    `clear` in class `java.util.AbstractList`

### addAll

    public boolean addAll(java.util.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. The behavior of this operation is undefined if the specified Collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified Collection is this list, and this list is nonempty.)

  Specified by:
    `addAll` in interface `java.util.Collection`
  Specified by:
    `addAll` in interface `java.util.List`
  Overrides:
    `addAll` in class `java.util.AbstractCollection`
  Parameters:
    `c` - the elements to be inserted into this list
  Returns:
    true if this list changed as a result of the call
  Throws:
    `java.lang.NullPointerException` - if the specified collection is null.

### addAll

    public boolean addAll(int index,
                          java.util.Collection c)

  Inserts all of the elements in the specified Collection into this list, starting at the specified position. Shift the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the list in the order that they are returned by the specified Collection's iterator.

  Specified by:
    `addAll` in interface `java.util.List`
  Overrides:
    `addAll` in class `java.util.AbstractList`
  Parameters:
    `index` - the index at which to insert first element from the specified collection
    `c` - the elements to be inserted into this list
  Returns:
    true if this list changed as a result of the call
  Throws:
    `java.lang.IndexOutOfBoundsException` - if index out of range
    `java.lang.NullPointerException` - if the specified Collection is null

### removeRange

    protected void removeRange(int fromIndex,
                               int toIndex)

  Removes from this list all of the elements whose indexes are between fromIndex, inclusive and toIndex, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by (toIndex - fromIndex) elements. (If toIndex==fromIndex, this operation has no effect.)

  Overrides:
    `removeRange` in class `java.util.AbstractList`
  Parameters:
    `fromIndex` - the index of first element to be removed
    `toIndex` - the index after last element to be removed.

### clone

    public java.lang.Object clone()

  Returns a shallow copy of this list instance. The elements themselves are not copied.

  Returns:
    a clone of this list instance

### effectiveIndex

    protected int effectiveIndex(int index)

  Calculate the effective index taking into account offsets and the circular nature of CircularArrayList.

  Parameters:
    `index` - the index to transform
  Returns:
    the effective index in the physical storage array

### rangeCheck

    protected void rangeCheck(int index)

  Check if the given index is in range. If not, throw an appropriate runtime exception.

  Parameters:
    `index` - the index to be checked for being between size() and 0 inclusive
  Throws:
    `java.lang.IndexOutOfBoundsException`

### ensureEffectiveIndex

    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.

  Parameters:
    `index` - the index to transform
  Returns:
    the effective index in the physical storage array
  Throws:
    `java.lang.IndexOutOfBoundsException`

### ensureCompactness

    protected boolean ensureCompactness()

  Ensure the representation of this list is appropriatly compact by shrinking if necessary.

  Returns:
    true if an actual compaction happened; false otherwise

### dump

    public void dump()

  Outputs information to standard output about representation for debugging purposes.

Overview | Package | Class | Tree | Index | Help

Oracle® Coherence Java API Reference
v3.5.3
E15583-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000, 2010, Oracle. All rights reserved.