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.
  • Field Details

    • mainCloseHandler

      private Runnable mainCloseHandler
      The main stream or a split iterator to close when the run() method will be invoked. This is initially the stream from which mainIterator has been created. However, if trySplit() has been invoked, then this handler may be the other Iterator instance which itself contains a reference to the stream to close, thus forming a chain.
    • mainIterator

      private final Spliterator<AbstractFeature> 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

      private AbstractFeature mainFeature
      A feature fetched from the mainIterator. The join operation will match this feature with zero, one or more features from the other side. A null value means that this feature needs to be retrieved with mainIterator.tryAdvance(…).
    • filteredStream

      private Stream<AbstractFeature> 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

      private Spliterator<AbstractFeature> filteredIterator
      Iterator for the filteredStream. A new iterator will be recreated every time a new feature from the main side is processed.
    • filteredFeature

      private AbstractFeature filteredFeature
      A feature fetched from the filteredIterator, or null if none.
  • Constructor Details

    • Iterator

      Iterator() throws DataStoreException
      Creates a new iterator. We do not use parallelized mainStream here because the accept(…) methods used by this Iterator cannot be invoked concurrently by different threads. It does not present parallelization at a different level since this Iterator supports trySplit(), so the Stream wrapping it can use parallelization.
      Throws:
      DataStoreException
    • Iterator

      private Iterator(Spliterator<AbstractFeature> it)
      Creates an iterator resulting from the call to trySplit().
  • Method Details

    • trySplit

      public Spliterator<AbstractFeature> 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. Returns null if this iterator cannot be partitioned.
      Specified by:
      trySplit in interface Spliterator<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 the trySplit requirement about prefix and suffix order is still fulfill even if the other stream is unordered.

      Specified by:
      characteristics in interface Spliterator<AbstractFeature>
    • estimateSize

      public long estimateSize()
      Estimated size is unknown.
      Specified by:
      estimateSize in interface Spliterator<AbstractFeature>
    • run

      public void run()
      Closes the streams used by this iterator, together with the streams used by any spliterator created by trySplit(). This method is registered to BaseStream.onClose(Runnable).
      Specified by:
      run in interface 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 current mainFeature.
    • forEachRemaining

      public void forEachRemaining(Consumer<? super AbstractFeature> action)
      Executes the given action on all remaining features in the JoinFeatureSet.
      Specified by:
      forEachRemaining in interface Spliterator<AbstractFeature>
    • accept

      public void accept(AbstractFeature feature)
      Callback for Spliterator.tryAdvance(this) on filteredIterator. Used by tryAdvance(Consumer) implementation only.
      Specified by:
      accept in interface Consumer<AbstractFeature>
    • tryAdvance

      public boolean tryAdvance(Consumer<? super AbstractFeature> action)
      Executes the given action on the next feature in the JoinFeatureSet.
      Specified by:
      tryAdvance in interface Spliterator<AbstractFeature>