Class LazySynchronizedIterator<E>

java.lang.Object
org.apache.sis.internal.util.AbstractIterator<E>
org.apache.sis.referencing.factory.LazySynchronizedIterator<E>
Type Parameters:
E - the type of elements to be returned by the iterator.
All Implemented Interfaces:
Iterator<E>

final class LazySynchronizedIterator<E> extends AbstractIterator<E>
An iterator over all elements given by an array of Iterable<E>, skipping null elements. All uses of an Iterable<E> (including its iterator) is synchronized on that Iterable instance.

Note that despite the above-cited synchronization, this iterator is not thread-safe: each thread needs to use its own iterator instance. However, provided that the above condition is met, different threads can safely use their iterators concurrently even if the underlying Iterables were not thread-safe, because of the synchronization on Iterable<E> instances.

Since:
0.7
Version:
0.7
  • Field Details

    • providers

      private final Iterable<? extends E>[] providers
      The providers of iterators. This array shall not be modified by LazySynchronizedSetIterator, since this is a direct reference to the array given to the constructor (not a copy).
    • providerIndex

      private int providerIndex
      Index of the Iterable<E> instance that provides the it value. This is also the instance to use as a synchronization lock.
    • it

      private Iterator<? extends E> it
      The iterator on which to delegate calls to hasNext() and AbstractIterator.next(). This iterator is provided by providers[providerIndex].iterator().
  • Constructor Details

    • LazySynchronizedIterator

      public LazySynchronizedIterator(Iterable<? extends E>[] providers)
      Creates a new iterator over all elements returned by the given providers. Null elements in the given array will be ignored.
      Parameters:
      providers - the providers of iterators. This array is not cloned.
  • Method Details

    • hasNext

      public boolean hasNext()
      Returns true if AbstractIterator.next() can return a non-null element. This method delegates to the iterators of all providers until one is found that return a non-null element.
      Returns:
      true if there is more elements to return.