org.geotools.feature.collection
Class SubFeatureCollection

Object
  extended by AbstractFeatureCollection
      extended by SubFeatureCollection
All Implemented Interfaces:
FeatureCollection<SimpleFeatureType,SimpleFeature>
Direct Known Subclasses:
SubFeatureList

public class SubFeatureCollection
extends AbstractFeatureCollection

Used as a reasonable default implementation for subCollection.

Note: to implementors, this is not optimal, please do your own thing - your users will thank you.

Author:
Jody Garnett, Refractions Research, Inc.
Module:

Field Summary
protected  FeatureCollection<SimpleFeatureType,SimpleFeature> collection
          Original Collection
protected  FilterFactory ff
           
protected  Filter filter
          Filter
 
Fields inherited from class AbstractFeatureCollection
id, listeners, open, schema
 
Constructor Summary
SubFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
           
SubFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> collection, Filter subfilter)
           
 
Method Summary
 void accepts(FeatureVisitor visitor, ProgressListener progress)
          Visit the contents of a feature collection.
 boolean add(SimpleFeature o)
          Implement to support modification.
 void clear()
          Removes all of the elements from this collection (optional operation).
 void close(FeatureIterator<SimpleFeature> close)
          Clean up after any resources associated with this FeatureIterator in a manner similar to JDO collections.
 void closeIterator(Iterator iterator)
          Please override to cleanup after your own iterators, and any used resources.
 FeatureCollection<SimpleFeatureType,SimpleFeature> collection()
           
protected  Filter createFilter()
          Override to implement subsetting
 FeatureIterator<SimpleFeature> features()
          Obtain a FeatureIterator of the Features within this collection.
protected  Filter filter()
           
 int getCount()
           
 String getID()
          ID used when serializing to GML
 boolean isEmpty()
           
 Iterator openIterator()
          Open a resource based Iterator, we will call close( iterator ).
 FeatureReader<SimpleFeatureType,SimpleFeature> reader()
           
 boolean remove(Object o)
          Removes a single instance of the specified element from this collection, if it is present (optional operation).
 int size()
          Returns the number of elements in this collection.
 FeatureCollection<SimpleFeatureType,SimpleFeature> sort(SortBy order)
          collection.subCollection( myFilter ).sort( {"foo","bar"} ); collection.subCollection( myFilter ).sort( "bar" ).sort("foo")
 FeatureCollection<SimpleFeatureType,SimpleFeature> subCollection(Filter filter)
          FeatureCollection "view" indicated by provided filter.
 
Methods inherited from class AbstractFeatureCollection
accepts, addAll, addAll, addListener, close, contains, containsAll, getBounds, getOpenIterators, getSchema, iterator, purge, removeAll, removeListener, retainAll, subList, toArray, toArray
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filter

protected Filter filter
Filter


collection

protected FeatureCollection<SimpleFeatureType,SimpleFeature> collection
Original Collection


ff

protected FilterFactory ff
Constructor Detail

SubFeatureCollection

public SubFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)

SubFeatureCollection

public SubFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> collection,
                            Filter subfilter)
Method Detail

openIterator

public Iterator openIterator()
Description copied from class: AbstractFeatureCollection
Open a resource based Iterator, we will call close( iterator ).

Please subclass to provide your own iterator for the the ResourceCollection, note iterator() is implemented to call open() and track the results in for later purge().

Specified by:
openIterator in class AbstractFeatureCollection
Returns:
Iterator based on resource use

closeIterator

public void closeIterator(Iterator iterator)
Description copied from class: AbstractFeatureCollection
Please override to cleanup after your own iterators, and any used resources.

As an example if the iterator was working off a File then the inputstream should be closed.

Subclass must call super.close( close ) to allow the list of open iterators to be adjusted.

Specified by:
closeIterator in class AbstractFeatureCollection
Parameters:
iterator - Iterator, will not be null

size

public int size()
Description copied from class: AbstractFeatureCollection
Returns the number of elements in this collection.

Specified by:
size in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Specified by:
size in class AbstractFeatureCollection
Returns:
Number of items, or Interger.MAX_VALUE
See Also:
Collection.size()

filter

protected Filter filter()

createFilter

protected Filter createFilter()
Override to implement subsetting


features

public FeatureIterator<SimpleFeature> features()
Description copied from interface: FeatureCollection
Obtain a FeatureIterator of the Features within this collection.

The implementation of Collection must adhere to the rules of fail-fast concurrent modification. In addition (to allow for resource backed collections, the close( Iterator ) method must be called.

This is almost equivalent to:

  • a Type-Safe call to: getAttribute(getFeatureType().getAttributeType(0).getName()).iterator();.
  • A Java 5:Iterator<Feature>

Example (safe) use:

 FeatureIterator iterator=collection.features();
 try {
     while( iterator.hasNext()  ){
          Feature feature = iterator.next();
          System.out.println( feature.getID() );
     }
 }
 finally {
     collection.close( iterator );
 }
 

GML Note: The contents of this iterator are considered to be defined by featureMember tags (and/or the single allowed FeatureMembers tag). Please see getFeatureType for more details.

Specified by:
features in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Overrides:
features in class AbstractFeatureCollection
Returns:
A FeatureIterator.

close

public void close(FeatureIterator<SimpleFeature> close)
Description copied from interface: FeatureCollection
Clean up after any resources associated with this FeatureIterator in a manner similar to JDO collections.

Example (safe) use:

 Iterator iterator = collection.iterator();
 try {
     for( Iterator i=collection.iterator(); i.hasNext();){
          Feature feature = i.hasNext();
          System.out.println( feature.getID() );
     }
 }
 finally {
     collection.close( iterator );
 }
 

Specified by:
close in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Overrides:
close in class AbstractFeatureCollection

subCollection

public FeatureCollection<SimpleFeatureType,SimpleFeature> subCollection(Filter filter)
Description copied from interface: FeatureCollection
FeatureCollection "view" indicated by provided filter.

The contents of the returned FeatureCollection are determined by applying the provider Filter to the entire contents of this FeatureCollection. The result is "live" and modifications will be shared.

This method is used cut down on the number of filter based methods required for a useful FeatureCollection construct. The FeatureCollections returned really should be considered as a temporary "view" used to control the range of a removeAll, or modify operation.

Example Use:


 collection.subCollection( filter ).clear();
 
The above recommended use is agreement with the Collections API precident of List.subList( start, end ).

The results of subCollection:

  • are to be considered unordered
  • may be an ordered FeatureList if requested when sortBy is indicated

Specified by:
subCollection in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Overrides:
subCollection in class AbstractFeatureCollection
Returns:
FeatureCollection identified as subset.
See Also:
FeatureList

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Overrides:
isEmpty in class AbstractFeatureCollection
Returns:
true if this collection contains no elements.
See Also:
Collection.isEmpty()

accepts

public void accepts(FeatureVisitor visitor,
                    ProgressListener progress)
Description copied from interface: FeatureCollection
Visit the contents of a feature collection.

The order of traversal is dependent on the FeatureCollection implementation; some collections are able to make efficient use of an internal index in order to quickly visit features located in the same region.

Specified by:
accepts in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Overrides:
accepts in class AbstractFeatureCollection
Parameters:
visitor - Closure applied to each feature in turn.
progress - Used to report progress, may be used to interrupt the operation

sort

public FeatureCollection<SimpleFeatureType,SimpleFeature> sort(SortBy order)
Description copied from interface: FeatureCollection
collection.subCollection( myFilter ).sort( {"foo","bar"} ); collection.subCollection( myFilter ).sort( "bar" ).sort("foo")

Specified by:
sort in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Overrides:
sort in class AbstractFeatureCollection
Returns:
FeatureCollection sorted in the indicated order

add

public boolean add(SimpleFeature o)
Description copied from class: AbstractFeatureCollection
Implement to support modification.

Specified by:
add in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Overrides:
add in class AbstractFeatureCollection
Parameters:
o - element whose presence in this collection is to be ensured.
Returns:
true if the collection changed as a result of the call.
See Also:
Collection.add(Object)

clear

public void clear()
Description copied from class: AbstractFeatureCollection
Removes all of the elements from this collection (optional operation).

Specified by:
clear in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Overrides:
clear in class AbstractFeatureCollection
See Also:
Collection.clear()

remove

public boolean remove(Object o)
Description copied from class: AbstractFeatureCollection
Removes a single instance of the specified element from this collection, if it is present (optional operation).

Specified by:
remove in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Overrides:
remove in class AbstractFeatureCollection
Parameters:
o - element to be removed from this collection, if present.
Returns:
true if the collection contained the specified element.
See Also:
Collection.remove(Object)

getID

public String getID()
Description copied from interface: FeatureCollection
ID used when serializing to GML

Specified by:
getID in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Overrides:
getID in class AbstractFeatureCollection

reader

public FeatureReader<SimpleFeatureType,SimpleFeature> reader()
                                                      throws IOException
Throws:
IOException

getCount

public int getCount()
             throws IOException
Throws:
IOException

collection

public FeatureCollection<SimpleFeatureType,SimpleFeature> collection()
                                                              throws IOException
Throws:
IOException


Copyright © 1996-2009 Geotools. All Rights Reserved.