FeatureCollection is not a java.util.Collection
back in black
This page represents the current plan; for discussion please check the tracker link above.
History and Motivation
FeatureCollection needs to lighten up to be happy; the original FeatureCollection implementation was a java.util.Collection offering iterator based access to features stored in memory. When the data access layer was rewritten for DataStore the concept of a FeatureResults was introduced wich could be thought of as a "prepared statement" (able to fetch results each time it was asked). This is a nice light weight "streaming" model for data access that does not force us to load the data into memory.
The intension was to treat it a bit more like a Java ResultSet (so several iterators could be open against the same paged results). But the road to hell is paved with good intensions.
And the FeatureResults interface was in for some hell: 2.1.x Bring Back FeatureCollection was a last ditch community lead request to bring back the FeatureCollection api and allow iterators to be used (thus not existing current code). The compromise that was reached was to ask users to FeatureCollection.close( Iterator ) each iterator after use; so that we could still offer a nice streaming based approach to data access.
For GeoTools 2.5.x we made the migration to Java 5 and we could no longer allow FeatureCollection to implement java.util.Collection because of the new "for each" syntax did not offer a callback for us to close our iterators. Justin started Focus FeatureSource around FeatureReader and FeatureWriter, however all we had time for was the bare minimum to make Java 5 not a fatal opportunity for client code to leak memory.
Bring back FeatureResult
In the spirit of Bring Back FeatureCollection here is our last minuet 2.7.x request to complete the journey; formally recognise that FeatureCollection is not a java.util.Collection and turf Iterator access (and other concepts that mirror in memory storage).
Remove the Listeners
First up is the add/remove listeners; a recent code review shows that they are only implemented by the new JDBCNG FeatureCollection (because justin is apparently very responsible). Due to everyone else not being responsible we can safely remove these since no client code could of depended on being sent an event.
Asking for your feature collection to be "loaded" into a DefaultFeatureCollection is the currently documented way of avoiding all this streaming nonsense and loading your data into memory.
The result is documented to be a java.util.Collection that also implements FeatureCollection. This is the current migration path for those wishing to have an in memory collection.
We can offer this same migration path to anyone having trouble making the switch off iterator.
We may also wish to consider a different implementation for DefaultFeatureCollection:
- TreeSetFeatureCollection - is used currently and is slow
- ListFeatureCollection - is new and untested, but may be faster in day to day use?
- SpatialIndexFeatureCollection - cannot be modified once made; not a suitable replacement
Remove Iterator Methods
The following methods cover the care and feeding of Iterators:
We are removing the close(FeatureIterator) method as well as it already has a serviceable FeatureIterator.close() method (the method was only provided to ease transition to FeatureIterator).
Remove Collection Contents Methods
The following methods are used to update and modify the contents of an in memory Collection and do not fit with the "Prepaired Statement" model of a FeatureCollection.
getSchema and getDescriptor()
This is a long standing hole in the API, proposal written in response to questions from Ben: FeatureCollection Descriptor for FeatureMembers
It sounds like this is just an additional method:
May also consider making the api consistent?
What is Left?
Just focusing on SimpleFeatureCollection for expediency; you can imagine the proper superset:
- toArray methods are there on the off chance the implementation can provide a quick implementation? Is this another good intension? Probably. Could be replaced with a DataUtilities method
- subCollection & sort functionality have been covered by Query these days; and could be removed.
- contains and containsAll are interesting; would almost expect look up by FeatureId instead
- getID() is left from a time when FeatureCollection implemented Feature; it is still used when encoding
- getDescriptor is technically accurate; however we are used to working with FeatureType
- isEmpty() earns its keep; size() == 0 is not a replacement as you need to count the whole set
- with that in mind containsAll falls into the same idea; how to prevent a multi pass operation
- accepts earns its keep for Jody Garnett, Andrea Aime wants the javadocs cleaned up so it is obvious that the feature being visited is a Flyweight (ie the same object with just the values changing inside each time)
So the bare minimum that is functional is, if we want more we need to justify it:
Jody Garnett's preference: getSchema() out of habit, getID and getDescriptor seem to be user data to facility specific encoding/decoding tasks, I like the accepts method, and wish contains worked on one or more FeatureId.
This proposal is the subject of a grass roots revolution on the geotools-devel list; indeed the revolution is on going and will not be televised.
Voting has not started yet:
- Andrea Aime
- Ben Caradoc-Davies
- Christian Mueller
- Ian Turton
- Justin Deoliveira
- Jody Garnett (current OSGeo representative)
- Michael Bedward
- Simone Giannecchini
- Review DefaultFeatureCollection methods and javadocs and capture in new docs
- Review DefaultFeatureCollection internals, consider replacing internals to be lighter weight
- Migrate methods and javadocs to DefaultFeatureCollection
- Deprecate and move to DefaultFeatureCollection: iterator based methods, move javadocs to DefaultFeatureCollection
- Deprecate and move to DefaultFeatureCollection: add/remove listeners (as they were not implemented)
- Deprecate and move to DefaultFeatureCollection: Collection maintenance methods retainAll, add, addAll, remove, removeAll, etc..
- Remove deprecated methods from FeatureCollection interface; update docs to indicate DataUtilities.collection( featureCollection ) work around
- Migrate FeatureCollection docs to sphinx
- Write DefaultFeatureCollection docs in sphinx
Status not quo.
- Migration to new documentation system