Package com.tangosol.util
Class AbstractSafeLongArray.SafeIterator
- java.lang.Object
-
- com.tangosol.util.AbstractSafeLongArray.SafeIterator
-
- All Implemented Interfaces:
LongArray.Iterator<V>
,Iterator<V>
- Enclosing class:
- AbstractSafeLongArray<V>
protected class AbstractSafeLongArray.SafeIterator extends Object implements LongArray.Iterator<V>
A lock based LongArray Iterator. Note the implementation is thread-safe so long as the wrapped unsafe LongArray supports stable iteration when accessed from a single thread. Specifically that performing an add or remove operation directly against the LongArray while being iterated does not corrupt the state of either the LongArray or the Iterator. An alternate approach would be to maintain a write counter and to refresh the delegate iterator each time the write counter changes, the refresh would be cheap as it could use iterator(m_lastIndex).
-
-
Field Summary
Fields Modifier and Type Field Description protected LongArray.Iterator<V>
f_delegate
The delegate iterator.protected long
m_lIndexLast
The index associated with the last returned valueprotected Object
m_valueLast
The last value returned from the iterator.
-
Constructor Summary
Constructors Modifier Constructor Description protected
SafeIterator(LongArray<V> delegate, boolean fForward, long lIndexFrom)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
ensureValid()
Ensure that the cached value/index are valid.long
getIndex()
Returns the index of the current value, which is the value returned by the most recent call to the next method.V
getValue()
Returns the current value, which is the same value returned by the most recent call to the next method, or the most recent value passed to setValue if setValue were called after the next method.boolean
hasNext()
Returns true if the iteration has more elements.V
next()
Returns the next element in the iteration.void
remove()
Removes from the underlying collection the last element returned by the iterator (optional operation).V
setValue(V oValue)
Stores a new value at the current value index, returning the value that was replaced.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Field Detail
-
f_delegate
protected final LongArray.Iterator<V> f_delegate
The delegate iterator.
-
m_valueLast
protected Object m_valueLast
The last value returned from the iterator.
-
m_lIndexLast
protected long m_lIndexLast
The index associated with the last returned value
-
-
Method Detail
-
hasNext
public boolean hasNext()
Description copied from interface:LongArray.Iterator
Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)
-
next
public V next()
Description copied from interface:LongArray.Iterator
Returns the next element in the iteration.
-
getIndex
public long getIndex()
Description copied from interface:LongArray.Iterator
Returns the index of the current value, which is the value returned by the most recent call to the next method.- Specified by:
getIndex
in interfaceLongArray.Iterator<V>
- Returns:
- the index of the current value
-
getValue
public V getValue()
Description copied from interface:LongArray.Iterator
Returns the current value, which is the same value returned by the most recent call to the next method, or the most recent value passed to setValue if setValue were called after the next method.- Specified by:
getValue
in interfaceLongArray.Iterator<V>
- Returns:
- the current value
-
setValue
public V setValue(V oValue)
Description copied from interface:LongArray.Iterator
Stores a new value at the current value index, returning the value that was replaced. The index of the current value is obtainable by calling the getIndex method.- Specified by:
setValue
in interfaceLongArray.Iterator<V>
- Parameters:
oValue
- the new value to store- Returns:
- the replaced value
-
remove
public void remove()
Description copied from interface:LongArray.Iterator
Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.
-
ensureValid
protected void ensureValid()
Ensure that the cached value/index are valid.
-
-