Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


com.tangosol.util
Class CopyOnWriteLongArray

java.lang.Object
  extended by com.tangosol.util.CopyOnWriteLongArray

All Implemented Interfaces:
LongArray, java.io.Serializable, java.lang.Cloneable

public class CopyOnWriteLongArray
extends java.lang.Object
implements LongArray

A thread-safe variant of LongArray in which all mutating operations (e.g. add, set) are implemented by making a fresh copy of the underlying array.

Iterators over this LongArray are guaranteed to produce a safe-iteration and not to throw ConcurrentModificationException. The iterator will not reflect concurrent additions, removals, or changes to this array. Mutating operations on iterators themselves (e.g. remove, setValue) are not supported (and will throw UnsupportedOperationException).

Note: mutations on this LongArray are costly, but may be more efficient than alternatives when traversal operations vastly outnumber mutations. All mutating operations are synchronized, so concurrent mutation can be prevented by holding synchronization on this object.

Since:
Coherence 3.7
Author:
rhl 2010.09.09

Nested Class Summary
static class CopyOnWriteLongArray.UnmodifiableIterator
          Unmodifiable view of a LongArray.Iterator.

 

Nested classes/interfaces inherited from interface com.tangosol.util.LongArray
LongArray.Iterator

 

Field Summary
protected static LongArray EMPTY_ARRAY
          An empty placeholder array.

 

Fields inherited from interface com.tangosol.util.LongArray
NOT_FOUND

 

Constructor Summary
CopyOnWriteLongArray()
          Default constructor.
CopyOnWriteLongArray(java.lang.Class clazz)
          Construct a CopyOnWriteLongArray with an underlying array of the specified type.
CopyOnWriteLongArray(LongArray array)
          Construct a CopyOnWriteLongArray, initialized with the contents of the specified LongArray.

 

Method Summary
 long add(java.lang.Object oValue)
          Add the passed element value to the LongArray and return the index at which the element value was stored.
 void clear()
          Remove all nodes from the LongArray.
 java.lang.Object clone()
          Make a clone of the LongArray.
 boolean contains(java.lang.Object oValue)
          Determine if the LongArray contains the specified element.
 LongArray copyArray(LongArray array)
          Return a shallow copy of the specified LongArray.
 boolean exists(long lIndex)
          Determine if the specified index is in use.
 java.lang.Object get(long lIndex)
          Return the value stored at the specified index.
 long getFirstIndex()
          Determine the first index that exists in the LongArray.
protected  LongArray getInternalArray()
          Return the internal LongArray.
 long getLastIndex()
          Determine the last index that exists in the LongArray.
 int getSize()
          Determine the size of the LongArray.
 long indexOf(java.lang.Object oValue)
          Return the index in this LongArray of the first occurrence of the specified element, or NOT_FOUND if this LongArray does not contain the specified element.
 long indexOf(java.lang.Object oValue, long lIndex)
          Return the index in this LongArray of the first occurrence of the specified element such that (index >= lIndex), or NOT_FOUND if this LongArray does not contain the specified element.
 LongArray.Iterator instantiateUnmodifiableIterator(LongArray.Iterator iterator)
          Factory pattern: instantiate an UnmodifiableIterator.
 boolean isEmpty()
          Test for empty LongArray.
 LongArray.Iterator iterator()
          Obtain a LongArray.Iterator of the contents of the LongArray in order of increasing indices.
 LongArray.Iterator iterator(long lIndex)
          Obtain a LongArray.Iterator of the contents of the LongArray in order of increasing indices, starting at a particular index such that the first call to next will set the location of the iterator at the first existent index that is greater than or equal to the specified index, or will throw a NoSuchElementException if there is no such existent index.
 long lastIndexOf(java.lang.Object oValue)
          Return the index in this LongArray of the last occurrence of the specified element, or NOT_FOUND if this LongArray does not contain the specified element.
 long lastIndexOf(java.lang.Object oValue, long lIndex)
          Return the index in this LongArray of the last occurrence of the specified element such that (index <= lIndex), or NOT_FOUND if this LongArray does not contain the specified element.
 java.lang.Object remove(long lIndex)
          Remove the specified index from the LongArray, returning its associated value.
 LongArray.Iterator reverseIterator()
          Obtain a LongArray.Iterator of the contents of the LongArray in reverse order (decreasing indices).
 LongArray.Iterator reverseIterator(long lIndex)
          Obtain a LongArray.Iterator of the contents of the LongArray in reverse order (decreasing indices), starting at a particular index such that the first call to next will set the location of the iterator at the first existent index that is less than or equal to the specified index, or will throw a NoSuchElementException if there is no such existent index.
 java.lang.Object set(long lIndex, java.lang.Object oValue)
          Add the passed item to the LongArray at the specified index.
protected  void setInternalArray(LongArray array)
          Set the internal LongArray.

 

Methods inherited from interface com.tangosol.util.LongArray
equals, toString

 

Field Detail

EMPTY_ARRAY

protected static final LongArray EMPTY_ARRAY
An empty placeholder array. This array should not be mutated or exposed.

Constructor Detail

CopyOnWriteLongArray

public CopyOnWriteLongArray()
Default constructor.

CopyOnWriteLongArray

public CopyOnWriteLongArray(java.lang.Class clazz)
                     throws java.lang.IllegalAccessException,
                            java.lang.InstantiationException
Construct a CopyOnWriteLongArray with an underlying array of the specified type.
Parameters:
clazz - the type of the internal array; must implement LongArray and have a public no-arg constructor
Throws:
java.lang.ClassCastException - if the specified type does not implement LongArray
java.lang.IllegalAccessException - if the class or its no-arg constructor is not accessible
java.lang.InstantiationException - if the specified Class represents an abstract class or interface; or if the class does not have a no-arg constructor; or if the instantiation fails for some other reason.

CopyOnWriteLongArray

public CopyOnWriteLongArray(LongArray array)
Construct a CopyOnWriteLongArray, initialized with the contents of the specified LongArray.
Parameters:
array - the initial LongArray

Method Detail

getInternalArray

protected LongArray getInternalArray()
Return the internal LongArray.
Returns:
the internal LongArray

setInternalArray

protected void setInternalArray(LongArray array)
Set the internal LongArray.
Parameters:
array - the new internal LongArray

copyArray

public LongArray copyArray(LongArray array)
Return a shallow copy of the specified LongArray.
Parameters:
array - the array to be copied
Returns:
a shallow copy of the specified LongArray

get

public java.lang.Object get(long lIndex)
Return the value stored at the specified index.
Specified by:
get in interface LongArray
Parameters:
lIndex - a long index value
Returns:
the object stored at the specified index, or null

set

public java.lang.Object set(long lIndex,
                            java.lang.Object oValue)
Add the passed item to the LongArray at the specified index.

If the index is already used, the passed value will replace the current value stored with the key, and the replaced value will be returned.

It is expected that LongArray implementations will "grow" as necessary to support the specified index.

Specified by:
set in interface LongArray
Parameters:
lIndex - a long index value
oValue - the object to store at the specified index
Returns:
the object that was stored at the specified index, or null

add

public long add(java.lang.Object oValue)
Add the passed element value to the LongArray and return the index at which the element value was stored.
Specified by:
add in interface LongArray
Parameters:
oValue - the object to add to the LongArray
Returns:
the long index value at which the element value was stored

exists

public boolean exists(long lIndex)
Determine if the specified index is in use.
Specified by:
exists in interface LongArray
Parameters:
lIndex - a long index value
Returns:
true if a value (including null) is stored at the specified index, otherwise false

remove

public java.lang.Object remove(long lIndex)
Remove the specified index from the LongArray, returning its associated value.
Specified by:
remove in interface LongArray
Parameters:
lIndex - the index into the LongArray
Returns:
the associated value (which can be null) or null if the specified index is not in the LongArray

contains

public boolean contains(java.lang.Object oValue)
Determine if the LongArray contains the specified element.

More formally, returns true if and only if this LongArray contains at least one element e such that (o==null ? e==null : o.equals(e)).

Specified by:
contains in interface LongArray
Parameters:
oValue - element whose presence in this list is to be tested
Returns:
true if this list contains the specified element

clear

public void clear()
Remove all nodes from the LongArray.
Specified by:
clear in interface LongArray

isEmpty

public boolean isEmpty()
Test for empty LongArray.
Specified by:
isEmpty in interface LongArray
Returns:
true if LongArray has no nodes

getSize

public int getSize()
Determine the size of the LongArray.
Specified by:
getSize in interface LongArray
Returns:
the number of nodes in the LongArray

iterator

public LongArray.Iterator iterator()
Obtain a LongArray.Iterator of the contents of the LongArray in order of increasing indices.
Specified by:
iterator in interface LongArray
Returns:
an instance of LongArray.Iterator

iterator

public LongArray.Iterator iterator(long lIndex)
Obtain a LongArray.Iterator of the contents of the LongArray in order of increasing indices, starting at a particular index such that the first call to next will set the location of the iterator at the first existent index that is greater than or equal to the specified index, or will throw a NoSuchElementException if there is no such existent index.
Specified by:
iterator in interface LongArray
Parameters:
lIndex - the LongArray index to iterate from
Returns:
an instance of LongArray.Iterator

reverseIterator

public LongArray.Iterator reverseIterator()
Obtain a LongArray.Iterator of the contents of the LongArray in reverse order (decreasing indices).
Specified by:
reverseIterator in interface LongArray
Returns:
an instance of LongArray.Iterator

reverseIterator

public LongArray.Iterator reverseIterator(long lIndex)
Obtain a LongArray.Iterator of the contents of the LongArray in reverse order (decreasing indices), starting at a particular index such that the first call to next will set the location of the iterator at the first existent index that is less than or equal to the specified index, or will throw a NoSuchElementException if there is no such existent index.
Specified by:
reverseIterator in interface LongArray
Parameters:
lIndex - the LongArray index to iterate from
Returns:
an instance of LongArray.Iterator

getFirstIndex

public long getFirstIndex()
Determine the first index that exists in the LongArray.
Specified by:
getFirstIndex in interface LongArray
Returns:
the lowest long value that exists in this LongArray, or NOT_FOUND if the LongArray is empty

getLastIndex

public long getLastIndex()
Determine the last index that exists in the LongArray.
Specified by:
getLastIndex in interface LongArray
Returns:
the highest long value that exists in this LongArray, or NOT_FOUND if the LongArray is empty

indexOf

public long indexOf(java.lang.Object oValue)
Return the index in this LongArray of the first occurrence of the specified element, or NOT_FOUND if this LongArray does not contain the specified element.
Specified by:
indexOf in interface LongArray

indexOf

public long indexOf(java.lang.Object oValue,
                    long lIndex)
Return the index in this LongArray of the first occurrence of the specified element such that (index >= lIndex), or NOT_FOUND if this LongArray does not contain the specified element.
Specified by:
indexOf in interface LongArray

lastIndexOf

public long lastIndexOf(java.lang.Object oValue)
Return the index in this LongArray of the last occurrence of the specified element, or NOT_FOUND if this LongArray does not contain the specified element.
Specified by:
lastIndexOf in interface LongArray

lastIndexOf

public long lastIndexOf(java.lang.Object oValue,
                        long lIndex)
Return the index in this LongArray of the last occurrence of the specified element such that (index <= lIndex), or NOT_FOUND if this LongArray does not contain the specified element.
Specified by:
lastIndexOf in interface LongArray

clone

public java.lang.Object clone()
Make a clone of the LongArray. The element values are not deep-cloned.
Specified by:
clone in interface LongArray
Returns:
a clone of this LongArray object

instantiateUnmodifiableIterator

public LongArray.Iterator instantiateUnmodifiableIterator(LongArray.Iterator iterator)
Factory pattern: instantiate an UnmodifiableIterator.
Parameters:
iterator - the underlying iterator
Returns:
an UnmodifiableIterator

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.