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>
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 Iterable
s
were not thread-safe, because of the synchronization on Iterable<E>
instances.
- Since:
- 0.7
- Version:
- 0.7
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe iterator on which to delegate calls tohasNext()
andAbstractIterator.next()
.private int
Index of theIterable<E>
instance that provides theit
value.The providers of iterators.Fields inherited from class org.apache.sis.internal.util.AbstractIterator
next
-
Constructor Summary
ConstructorsConstructorDescriptionLazySynchronizedIterator
(Iterable<? extends E>[] providers) Creates a new iterator over all elements returned by the given providers. -
Method Summary
Modifier and TypeMethodDescriptionboolean
hasNext()
Returnstrue
ifAbstractIterator.next()
can return a non-null element.Methods inherited from class org.apache.sis.internal.util.AbstractIterator
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
-
Field Details
-
providers
The providers of iterators. This array shall not be modified byLazySynchronizedSetIterator
, since this is a direct reference to the array given to the constructor (not a copy). -
providerIndex
private int providerIndexIndex of theIterable<E>
instance that provides theit
value. This is also the instance to use as a synchronization lock. -
it
The iterator on which to delegate calls tohasNext()
andAbstractIterator.next()
. This iterator is provided byproviders[providerIndex].iterator()
.
-
-
Constructor Details
-
LazySynchronizedIterator
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()Returnstrue
ifAbstractIterator.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.
-