Package org.cactoos.iterator
Class Synced<T>
- java.lang.Object
-
- org.cactoos.iterator.Synced<T>
-
- Type Parameters:
T
- The type of the iterator.
- All Implemented Interfaces:
Iterator<T>
public final class Synced<T> extends Object implements Iterator<T>
SynchronizedIterator
implementation using aReadWriteLock
either provided to the constructor or an internally createdReentrantReadWriteLock
.The
ReadWriteLock
is used to synchronize read calls tohasNext()
against write calls tonext()
and write calls to any other read or write calls.Objects of this class are thread-safe.
- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasNext()
T
next()
-
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, remove
-
-
-
-
Constructor Detail
-
Synced
public Synced(Iterator<? extends T> iterator)
Ctor.- Parameters:
iterator
- The iterator to synchronize access to.
-
Synced
public Synced(ReadWriteLock lock, Iterator<? extends T> iterator)
Ctor.- Parameters:
lock
- The lock to use for synchronization.iterator
- The iterator to synchronize access to.
-
-