Class CopyOnWriteLongArray<V>
- All Implemented Interfaces:
LongArray<V>
,Serializable
,Cloneable
,Iterable<V>
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.
This data-structure is not suitable to frequent updates, or updates on large
data-sets see ReadHeavyLongArray
for a more suitable alternative for
such cases.
- Since:
- Coherence 3.7
- Author:
- rhl 2010.09.09
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Unmodifiable view of a LongArray.Iterator.Nested classes/interfaces inherited from interface com.tangosol.util.LongArray
LongArray.Iterator<V>
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDefault constructor.CopyOnWriteLongArray
(LongArray<V> array) Construct a CopyOnWriteLongArray, initialized with the contents of the specified LongArray.CopyOnWriteLongArray
(Class<? extends LongArray<V>> clazz) Construct a CopyOnWriteLongArray with an underlying array of the specified type. -
Method Summary
Modifier and TypeMethodDescriptionlong
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.clone()
Make a clone of the LongArray.Return a shallow copy of the specified LongArray.delegate()
Return the internal LongArray.instantiateUnmodifiableIterator
(LongArray.Iterator<V> iterator) Factory pattern: instantiate an UnmodifiableIterator.iterator()
Obtain a LongArray.Iterator of the contents of the LongArray in order of increasing indices.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.remove
(long lIndex) Remove the specified index from the LongArray, returning its associated value.void
remove
(long lIndexFrom, long lIndexTo) Remove all nodes in the specified range.Obtain a LongArray.Iterator of the contents of the LongArray in reverse order (decreasing indices).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.Add the passed item to the LongArray at the specified index.protected void
setDelegate
(LongArray<V> array) Set the internal LongArray.Methods inherited from class com.tangosol.util.WrapperCollections.AbstractWrapperLongArray
ceiling, ceilingIndex, contains, exists, floor, floorIndex, get, getFirstIndex, getLastIndex, getSize, indexOf, indexOf, isEmpty, lastIndexOf, lastIndexOf
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
EMPTY_ARRAY
An empty placeholder array. This array should not be mutated or exposed.
-
-
Constructor Details
-
CopyOnWriteLongArray
public CopyOnWriteLongArray()Default constructor. -
CopyOnWriteLongArray
public CopyOnWriteLongArray(Class<? extends LongArray<V>> clazz) throws IllegalAccessException, 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:
ClassCastException
- if the specified type does not implement LongArrayIllegalAccessException
- if the class or its no-arg constructor is not accessibleInstantiationException
- 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
Construct a CopyOnWriteLongArray, initialized with the contents of the specified LongArray.- Parameters:
array
- the initial LongArray
-
-
Method Details
-
delegate
Return the internal LongArray.- Specified by:
delegate
in classWrapperCollections.AbstractWrapperLongArray<V>
- Returns:
- the internal LongArray
-
setDelegate
Set the internal LongArray.- Parameters:
array
- the new internal LongArray
-
copyArray
Return a shallow copy of the specified LongArray.- Parameters:
array
- the array to be copied- Returns:
- a shallow copy of the specified LongArray
-
set
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.
-
add
Add the passed element value to the LongArray and return the index at which the element value was stored. -
remove
Remove the specified index from the LongArray, returning its associated value. -
remove
public void remove(long lIndexFrom, long lIndexTo) Remove all nodes in the specified range. -
clear
public void clear()Remove all nodes from the LongArray. -
iterator
Obtain a LongArray.Iterator of the contents of the LongArray in order of increasing indices. -
iterator
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. -
reverseIterator
Obtain a LongArray.Iterator of the contents of the LongArray in reverse order (decreasing indices).- Specified by:
reverseIterator
in interfaceLongArray<V>
- Overrides:
reverseIterator
in classWrapperCollections.AbstractWrapperLongArray<V>
- Returns:
- an instance of LongArray.Iterator
-
reverseIterator
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 interfaceLongArray<V>
- Overrides:
reverseIterator
in classWrapperCollections.AbstractWrapperLongArray<V>
- Parameters:
lIndex
- the LongArray index to iterate from- Returns:
- an instance of LongArray.Iterator
-
clone
Make a clone of the LongArray. The element values are not deep-cloned. -
instantiateUnmodifiableIterator
Factory pattern: instantiate an UnmodifiableIterator.- Parameters:
iterator
- the underlying iterator- Returns:
- an UnmodifiableIterator
-