Class 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>
    Synchronized Iterator implementation using a ReadWriteLock either provided to the constructor or an internally created ReentrantReadWriteLock.

    The ReadWriteLock is used to synchronize read calls to hasNext() against write calls to next() and write calls to any other read or write calls.

    Objects of this class are thread-safe.

    Since:
    1.0
    • 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.
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface Iterator<T>
      • next

        public T next()
        Specified by:
        next in interface Iterator<T>