Hello all
We have recently committed on trunk a few DataStore implementations
capable to read Features. A Feature can been seen as some kind of
geographic object (a point, a geometry, a coverage) associated to
arbitrary attributes (e.g. a geometry representing a land parcel,
together with the land owner name). Currently, the Features read by
Apache SIS are mostly points, but the API [1] should be able to handle
more complex types (except Moving Features - to be the subject of
another discussion). However I'm not sure yet how they should be
returned to the user.
Current DataStore API [2] does not yet provide a public method for
returning features. For now, there is an internal (non-public)
FeatureStore class [3] with the following method:
public abstract Stream<Feature> features() throws DataStoreException;
Being in an internal package, this is not yet committed API. This method
is very likely to evolve. In particular a future version is likely to
require some Query argument for filtering the stream to the features
included in some bounding boxes or other conditions. But my first
interrogation is what should be the return type. In current proposal,
this is a Stream of Features. An alternative could be a Collection of
Features. I see the following pros and cons:
* Collection<Feature>:
o Pro:
+ Relatively easy to implement
+ Can iterate over the same collection more than once
+ Available on all supported Java versions.
o Con:
+ Collection.size() may be costly if its force the DataStore
to scan the whole file
+ Does not extend AutoCloseable
* Stream<Feature>:
o Pro:
+ No requirement to provide an accurate Feature count
+ Extends AutoCloseable, so it can be used safely in contexts
where the Stream reads Features on-the-fly.
o Con:
+ If we need to go beyond what we can do through Spliterator,
providing our own Stream implementation requires more code
than providing our own Collection implementation.
+ Doing a second iteration over the Features require creating
a new Stream.
+ Require JDK8
Is there any though? My proposal would be to go with Stream<Feature>,
but only in internal API for one or two SIS release so we can change our
mind before to commit to a public API.
Martin
[1]http://sis.apache.org/apidocs/org/apache/sis/feature/package-summary.html
[2]http://sis.apache.org/apidocs/org/apache/sis/storage/DataStore.html
[3]http://svn.apache.org/repos/asf/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/FeatureStore.java