Class FeatureIterator
java.lang.Object
org.apache.sis.internal.storage.csv.FeatureIterator
- All Implemented Interfaces:
Spliterator<AbstractFeature>
- Direct Known Subclasses:
MovingFeatureIterator
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.Spliterator
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T extends Object,
T_CONS extends Object, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>> -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final ObjectConverter<String,
?>[] Converters from string representations to the values to store in thevalues
array.(package private) final String[]
Name of the property where to store a value.private AtomicInteger
Number of calls totrySplit()
.(package private) final Store
Connection to the CSV file.(package private) static final int
Index of the column containing trajectory coordinates.(package private) final Object[]
All values found in a row.Fields inherited from interface java.util.Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
FeatureIterator
(FeatureIterator other) Creates a new iterator using the same configuration than the given iterator.(package private)
FeatureIterator
(Store store) Creates a new iterator. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the characteristics of the iteration over feature instances.long
We do not know the number of features.void
forEachRemaining
(Consumer<? super AbstractFeature> action) Executes the given action on all remaining features.private boolean
read
(Consumer<? super AbstractFeature> action, boolean all) Executes the given action for the next feature or for all remaining features.boolean
tryAdvance
(Consumer<? super AbstractFeature> action) Executes the given action only on the next feature, if any.trySplit()
If this spliterator can be partitioned, returns aSpliterator
covering elements.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
-
TRAJECTORY_COLUMN
static final int TRAJECTORY_COLUMNIndex of the column containing trajectory coordinates. Columns before the trajectory are Moving Feature identifiermfIdRef
, start time and end time.- See Also:
-
store
Connection to the CSV file. -
propertyNames
Name of the property where to store a value. This array be considered unmodifiable and may be shared between manyIter
instances. -
converters
Converters from string representations to the values to store in thevalues
array. This array be considered unmodifiable and may be shared between manyIter
instances. -
values
All values found in a row. We need to remember those values between different executions of thetryAdvance(Consumer)
method because the Moving Feature Specification said: "If the value equals the previous value, the text for the value can be omitted." -
splitCount
Number of calls totrySplit()
. Created only if needed.
-
-
Constructor Details
-
FeatureIterator
FeatureIterator(Store store) Creates a new iterator. -
FeatureIterator
Creates a new iterator using the same configuration than the given iterator. This constructor is fortrySplit()
implementation only.
-
-
Method Details
-
trySplit
If this spliterator can be partitioned, returns aSpliterator
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 interfaceSpliterator<AbstractFeature>
-
tryAdvance
Executes the given action only on the next feature, if any.- Specified by:
tryAdvance
in interfaceSpliterator<AbstractFeature>
-
forEachRemaining
Executes the given action on all remaining features.- Specified by:
forEachRemaining
in interfaceSpliterator<AbstractFeature>
-
read
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 fortryAdvance(Consumer)
andforEachRemaining(Consumer)
implementations.Multi-threading
Iter
does not need to be thread-safe, so we do not perform synchronization for itsvalues
. Accesses toStore
fields need to be thread-safe, but this method uses only immutable or thread-safe objects fromStore
, so there is no need forsynchronize(Store.this)
statement. The only object that need synchronization isStore.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 interfaceSpliterator<AbstractFeature>
-
characteristics
public int characteristics()Returns the characteristics of the iteration over feature instances. The iteration isSpliterator.NONNULL
(i.e.tryAdvance(Consumer)
is not allowed to return null value) andSpliterator.IMMUTABLE
(i.e. we do not support modification of the CSV file while an iteration is in progress). The iteration is not declaredSpliterator.ORDERED
becausetrySplit()
does not return a strict prefix of the elements.- Specified by:
characteristics
in interfaceSpliterator<AbstractFeature>
- Returns:
- characteristics of iteration over the features in the CSV file.
-