Package org.apache.sis.storage.aggregate
Class JoinFeatureSet.Iterator
java.lang.Object
org.apache.sis.storage.aggregate.JoinFeatureSet.Iterator
- All Implemented Interfaces:
Runnable
,Consumer<AbstractFeature>
,Spliterator<AbstractFeature>
- Enclosing class:
JoinFeatureSet
private final class JoinFeatureSet.Iterator
extends Object
implements Spliterator<AbstractFeature>, Consumer<AbstractFeature>, Runnable
Iterator over the features resulting from the inner or outer join operation.
The
run()
method disposes the resources.-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.Spliterator
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T,
T_CONS, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AbstractFeature
A feature fetched from thefilteredIterator
, ornull
if none.private Spliterator
<AbstractFeature> Iterator for thefilteredStream
.private Stream
<AbstractFeature> The stream over features in the other (usually right) side.private Runnable
The main stream or a split iterator to close when therun()
method will be invoked.private AbstractFeature
A feature fetched from themainIterator
.private final Spliterator
<AbstractFeature> An iterator over all features in the "main" (usually left) side.Fields inherited from interface java.util.Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED
-
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
Iterator()
Creates a new iterator.private
Creates an iterator resulting from the call totrySplit()
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(AbstractFeature feature) Callback forSpliterator.tryAdvance(this)
onfilteredIterator
.int
Specifies that the iterator will return only non-null elements.private void
Invoked when iteration on the filtered stream ended, before to move on the next feature of the main stream.private void
Creates a new iterator over the filtered set of features (usually the right side).long
Estimated size is unknown.void
forEachRemaining
(Consumer<? super AbstractFeature> action) Executes the given action on all remaining features in theJoinFeatureSet
.void
run()
Closes the streams used by this iterator, together with the streams used by any spliterator created bytrySplit()
.boolean
tryAdvance
(Consumer<? super AbstractFeature> action) Executes the given action on the next feature in theJoinFeatureSet
.trySplit()
If this iterator can be partitioned, returns a spliterator covering a prefix of the feature set.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Spliterator
getComparator, getExactSizeIfKnown, hasCharacteristics
-
Field Details
-
mainCloseHandler
The main stream or a split iterator to close when therun()
method will be invoked. This is initially the stream from whichmainIterator
has been created. However, iftrySplit()
has been invoked, then this handler may be the otherIterator
instance which itself contains a reference to the stream to close, thus forming a chain. -
mainIterator
An iterator over all features in the "main" (usually left) side. The "main" side is the side which may include all features: in a "left outer join" this is the left side, and in a "right outer join" this is the right side. For inner join we arbitrarily take the left side in accordance with public class javadoc, which suggests to put the most costly or larger set on the left side.Only one iteration will be performed on those features, contrarily to the other side where we may iterate over the same elements many times.
-
mainFeature
A feature fetched from themainIterator
. The join operation will match this feature with zero, one or more features from the other side. Anull
value means that this feature needs to be retrieved withmainIterator.tryAdvance(…)
. -
filteredStream
The stream over features in the other (usually right) side. A new stream will be created every time a new feature from the main side is processed. For this reason, it should be the cheapest stream if possible. -
filteredIterator
Iterator for thefilteredStream
. A new iterator will be recreated every time a new feature from the main side is processed. -
filteredFeature
A feature fetched from thefilteredIterator
, ornull
if none.
-
-
Constructor Details
-
Iterator
Iterator() throws DataStoreExceptionCreates a new iterator. We do not use parallelizedmainStream
here because theaccept(…)
methods used by thisIterator
cannot be invoked concurrently by different threads. It does not present parallelization at a different level since thisIterator
supportstrySplit()
, so theStream
wrapping it can use parallelization.- Throws:
DataStoreException
-
Iterator
Creates an iterator resulting from the call totrySplit()
.
-
-
Method Details
-
trySplit
If this iterator can be partitioned, returns a spliterator covering a prefix of the feature set. Upon return from this method, this iterator will cover a suffix of the feature set. Returnsnull
if this iterator cannot be partitioned.- Specified by:
trySplit
in interfaceSpliterator<AbstractFeature>
-
characteristics
public int characteristics()Specifies that the iterator will return only non-null elements. Whether those elements will be ordered depends on whether the main iterator provides ordered elements in the first place.NOTE: to be strict, we should check if the "filtered" stream is also ordered. But this is more difficult to check. Current implementation assumes that if the "mean" stream is ordered, then the other stream is ordered too. Furthermore, the
trySplit()
method works only on the main stream, so at least thetrySplit
requirement about prefix and suffix order is still fulfill even if the other stream is unordered.- Specified by:
characteristics
in interfaceSpliterator<AbstractFeature>
-
estimateSize
public long estimateSize()Estimated size is unknown.- Specified by:
estimateSize
in interfaceSpliterator<AbstractFeature>
-
run
public void run()Closes the streams used by this iterator, together with the streams used by any spliterator created bytrySplit()
. This method is registered toBaseStream.onClose(Runnable)
. -
closeFilteredIterator
private void closeFilteredIterator()Invoked when iteration on the filtered stream ended, before to move on the next feature of the main stream. This method is idempotent: it has no effect if the stream is already closed. -
createFilteredIterator
private void createFilteredIterator()Creates a new iterator over the filtered set of features (usually the right side). The filtering condition is determined by the currentmainFeature
. -
forEachRemaining
Executes the given action on all remaining features in theJoinFeatureSet
.- Specified by:
forEachRemaining
in interfaceSpliterator<AbstractFeature>
-
accept
Callback forSpliterator.tryAdvance(this)
onfilteredIterator
. Used bytryAdvance(Consumer)
implementation only.- Specified by:
accept
in interfaceConsumer<AbstractFeature>
-
tryAdvance
Executes the given action on the next feature in theJoinFeatureSet
.- Specified by:
tryAdvance
in interfaceSpliterator<AbstractFeature>
-