Class FeatureIterator

java.lang.Object
org.apache.sis.internal.storage.csv.FeatureIterator
All Implemented Interfaces:
Spliterator<AbstractFeature>
Direct Known Subclasses:
MovingFeatureIterator

class FeatureIterator extends Object implements Spliterator<AbstractFeature>
Base implementation of iterators returned by Store.features(boolean). This base class returns one feature per line. For example, iteration over the following file will produce 4 Feature instances, even if there is actually only three distinct instances because the feature "a" is splitted on 2 lines: Multi-threading: Iter is not thread-safe. However, many Iter instances can be used concurrently for the same Store instance.
Since:
0.7
Version:
0.8
  • Field Details

    • TRAJECTORY_COLUMN

      static final int TRAJECTORY_COLUMN
      Index of the column containing trajectory coordinates. Columns before the trajectory are Moving Feature identifier mfIdRef, start time and end time.
      See Also:
    • store

      final Store store
      Connection to the CSV file.
    • propertyNames

      final String[] propertyNames
      Name of the property where to store a value. This array be considered unmodifiable and may be shared between many Iter instances.
    • converters

      final ObjectConverter<String,?>[] converters
      Converters from string representations to the values to store in the values array. This array be considered unmodifiable and may be shared between many Iter instances.
    • values

      final Object[] values
      All values found in a row. We need to remember those values between different executions of the tryAdvance(Consumer) method because the Moving Feature Specification said: "If the value equals the previous value, the text for the value can be omitted."
    • splitCount

      private AtomicInteger splitCount
      Number of calls to trySplit(). Created only if needed.
  • Constructor Details

    • FeatureIterator

      FeatureIterator(Store store)
      Creates a new iterator.
    • FeatureIterator

      private FeatureIterator(FeatureIterator other)
      Creates a new iterator using the same configuration than the given iterator. This constructor is for trySplit() implementation only.
  • Method Details

    • trySplit

      public Spliterator<AbstractFeature> trySplit()
      If this spliterator can be partitioned, returns a Spliterator covering elements. This method does not make any guarantees about iteration order; i.e. the returned iterator is not guaranteed to cover a strict prefix of the elements.
      Specified by:
      trySplit in interface Spliterator<AbstractFeature>
    • tryAdvance

      public boolean tryAdvance(Consumer<? super AbstractFeature> action)
      Executes the given action only on the next feature, if any.
      Specified by:
      tryAdvance in interface Spliterator<AbstractFeature>
    • forEachRemaining

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

      private boolean read(Consumer<? super AbstractFeature> action, boolean all) throws IOException
      Executes the given action for the next feature or for all remaining features. The features are assumed static, with one feature per line. This method is for tryAdvance(Consumer) and forEachRemaining(Consumer) implementations.

      Multi-threading

      Iter does not need to be thread-safe, so we do not perform synchronization for its values. Accesses to Store fields need to be thread-safe, but this method uses only immutable or thread-safe objects from Store, so there is no need for synchronize(Store.this) statement. The only object that need synchronization is Store.source, which is already synchronized.
      Parameters:
      action - the action to execute.
      all - true for executing the given action on all remaining features.
      Returns:
      false if there are no remaining features after this method call.
      Throws:
      IOException - if an I/O error occurred while reading a feature.
      IllegalArgumentException - if parsing of a number failed, or other error.
      DateTimeException - if parsing of a date failed.
    • estimateSize

      public long estimateSize()
      We do not know the number of features.
      Specified by:
      estimateSize in interface Spliterator<AbstractFeature>
    • characteristics

      public int characteristics()
      Returns the characteristics of the iteration over feature instances. The iteration is Spliterator.NONNULL (i.e. tryAdvance(Consumer) is not allowed to return null value) and Spliterator.IMMUTABLE (i.e. we do not support modification of the CSV file while an iteration is in progress). The iteration is not declared Spliterator.ORDERED because trySplit() does not return a strict prefix of the elements.
      Specified by:
      characteristics in interface Spliterator<AbstractFeature>
      Returns:
      characteristics of iteration over the features in the CSV file.