Represents a collection of features.
Implementations (and client code) should adhere to the rules set forth
by java.util.Collection. That is, some methods are
optional to implement, and may throw an UnsupportedOperationException.
FeatureCollection house rules:
- FeatureCollection.close( iterator ) must be called (see example below)
- Features are not specifically ordered within the FeatureCollection (see FeatureList)
- Two instances cannot exist with the same Feature ID (Feature contract)
- (unsure) the same Instance can be in the collection more then once
In programmer speak a FeatureCollection is a "Bag" with an index based ID.
Life Cycle of Iterator
We have also adopted an additional constraint on the use of iterator.
You must call FeatureCollection.close( iterator ) to allow FeatureCollection
to clean up any operating system resources used to acces information.
Example (safe) use:
Iterator iterator = collection.iterator();
try {
for( Iterator i=collection.iterator(); i.hasNext();){
Feature feature = (Feature) i.hasNext();
System.out.println( feature.getID() );
}
}
finally {
collection.close( iterator );
}
Handy Tip: Although many resource backed collections will choose
to release resources at when the iterator has reached the end of its contents
this is not something you should rely on.
Notes for FeatureCollection Implementors
Many users will be treating this as a straight forward Collection,
there code will break often enough due to latency - try and close
up resources for them when you can detect that an Iterator is not
useful anymore.
Collections are used in two fashions, basically as you see them,
and also as "range" for common opperations. You can see this with
List.subCollection( Filter ). Existing RnD effort is
going towards supporting this kind of use at the FeatureCollection
level.
See Also: java.util.Collection, org.geotools.Feature author: Ian Turton, CCG author: Rob Hranac, VFNY author: Ian Schneider, USDA-ARS author: Jody Garnett, Refractions Research, Inc. version: $Id: FeatureCollection.java 28248 2007-12-04 17:47:43Z jgarnett $ |