public class CopyOnWriteLongArray<V> extends WrapperCollections.AbstractWrapperLongArray<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.
Modifier and Type | Class and Description |
---|---|
static class |
CopyOnWriteLongArray.UnmodifiableIterator<V>
Unmodifiable view of a LongArray.Iterator.
|
LongArray.Iterator<V>
Modifier and Type | Field and Description |
---|---|
protected static LongArray |
EMPTY_ARRAY
An empty placeholder array.
|
Constructor and Description |
---|
CopyOnWriteLongArray()
Default constructor.
|
CopyOnWriteLongArray(Class<? extends LongArray<V>> clazz)
Construct a CopyOnWriteLongArray with an underlying array of the specified
type.
|
CopyOnWriteLongArray(LongArray<V> array)
Construct a CopyOnWriteLongArray, initialized with the contents of the
specified LongArray.
|
Modifier and Type | Method and Description |
---|---|
long |
add(V 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.
|
CopyOnWriteLongArray<V> |
clone()
Make a clone of the LongArray.
|
LongArray<V> |
copyArray(LongArray<V> array)
Return a shallow copy of the specified LongArray.
|
protected LongArray<V> |
delegate()
Return the internal LongArray.
|
LongArray.Iterator<V> |
instantiateUnmodifiableIterator(LongArray.Iterator<V> iterator)
Factory pattern: instantiate an UnmodifiableIterator.
|
LongArray.Iterator<V> |
iterator()
Obtain a LongArray.Iterator of the contents of the LongArray in
order of increasing indices.
|
LongArray.Iterator<V> |
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.
|
V |
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.
|
LongArray.Iterator<V> |
reverseIterator()
Obtain a LongArray.Iterator of the contents of the LongArray in
reverse order (decreasing indices).
|
LongArray.Iterator<V> |
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.
|
V |
set(long lIndex,
V oValue)
Add the passed item to the LongArray at the specified index.
|
protected void |
setDelegate(LongArray<V> array)
Set the internal LongArray.
|
ceiling, ceilingIndex, contains, exists, floor, floorIndex, get, getFirstIndex, getLastIndex, getSize, indexOf, indexOf, isEmpty, lastIndexOf, lastIndexOf
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
protected static final LongArray EMPTY_ARRAY
public CopyOnWriteLongArray()
public CopyOnWriteLongArray(Class<? extends LongArray<V>> clazz) throws IllegalAccessException, InstantiationException
clazz
- the type of the internal array; must implement LongArray
and have a public no-arg constructorClassCastException
- 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.protected LongArray<V> delegate()
delegate
in class WrapperCollections.AbstractWrapperLongArray<V>
protected void setDelegate(LongArray<V> array)
array
- the new internal LongArraypublic LongArray<V> copyArray(LongArray<V> array)
array
- the array to be copiedpublic V set(long lIndex, V oValue)
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.
public long add(V oValue)
public V remove(long lIndex)
public void remove(long lIndexFrom, long lIndexTo)
public void clear()
public LongArray.Iterator<V> iterator()
public LongArray.Iterator<V> iterator(long lIndex)
public LongArray.Iterator<V> reverseIterator()
reverseIterator
in interface LongArray<V>
reverseIterator
in class WrapperCollections.AbstractWrapperLongArray<V>
public LongArray.Iterator<V> reverseIterator(long lIndex)
reverseIterator
in interface LongArray<V>
reverseIterator
in class WrapperCollections.AbstractWrapperLongArray<V>
lIndex
- the LongArray index to iterate frompublic CopyOnWriteLongArray<V> clone()
public LongArray.Iterator<V> instantiateUnmodifiableIterator(LongArray.Iterator<V> iterator)
iterator
- the underlying iterator