org.geotools.feature.collection
Class AdaptorFeatureCollection

Object
  extended by AdaptorFeatureCollection
All Implemented Interfaces:
FeatureCollection<SimpleFeatureType,SimpleFeature>

public abstract class AdaptorFeatureCollection
extends Object
implements FeatureCollection<SimpleFeatureType,SimpleFeature>

Implement a feature collection just based on provision of iterator.

Author:
Jody Garnett (Refractions Research Inc)
Module:
modules/library/main (gt-main.jar)

Field Summary
protected  String id
          id used when serialized to gml
protected  List listeners
          listeners
protected  Set open
          Set of open resource iterators
protected  SimpleFeatureType schema
           
 
Constructor Summary
AdaptorFeatureCollection(String id, SimpleFeatureType memberType)
           
 
Method Summary
 void accepts(FeatureVisitor visitor, ProgressListener progress)
          Accepts a visitor, which then visits each feature in the collection.
 boolean add(SimpleFeature o)
          Implement to support modification.
 boolean addAll(Collection c)
          Adds all of the elements in the specified collection to this collection (optional operation).
 boolean addAll(FeatureCollection c)
           
 void addListener(CollectionListener listener)
          Adds a listener for collection events.
 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 close(Iterator close)
          Clean up after any resources assocaited with this iteartor in a manner similar to JDO collections.
 void closeIterator(FeatureIterator<SimpleFeature> close)
           
protected abstract  void closeIterator(Iterator<SimpleFeature> close)
          Please override to cleanup after your own iterators, and any used resources.
 boolean contains(Object o)
          Returns true if this collection contains the specified element.
 boolean containsAll(Collection c)
          Returns true if this collection contains all of the elements in the specified collection.
 FeatureIterator<SimpleFeature> features()
          Obtain a FeatureIterator of the Features within this collection.
 ReferencedEnvelope getBounds()
          Subclasses need to override this.
 String getID()
          ID used when serializing to GML
 Set getOpenIterators()
          Returns the set of open iterators.
 SimpleFeatureType getSchema()
          The schema for the child features of this collection.
 boolean isEmpty()
           
 Iterator<SimpleFeature> iterator()
          Please implement!
protected abstract  Iterator<SimpleFeature> openIterator()
          Open an Iterator, we will call close( iterator ).
 void purge()
          Close any outstanding resources released by this resources.
 boolean remove(Object o)
          Removes a single instance of the specified element from this collection, if it is present (optional operation).
 boolean removeAll(Collection c)
          Removes from this collection all of its elements that are contained in the specified collection (optional operation).
 void removeListener(CollectionListener listener)
          Removes a listener for collection events.
 boolean retainAll(Collection c)
          Retains only the elements in this collection that are contained in the specified collection (optional operation).
abstract  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.
 FeatureCollection<SimpleFeatureType,SimpleFeature> subList(Filter filter)
           
 Object[] toArray()
          Array of all the elements.
 Object[] toArray(Object[] a)
           
 String toString()
          Returns a string representation of this collection.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

open

protected final Set open
Set of open resource iterators


listeners

protected List listeners
listeners


id

protected String id
id used when serialized to gml


schema

protected SimpleFeatureType schema
Constructor Detail

AdaptorFeatureCollection

public AdaptorFeatureCollection(String id,
                                SimpleFeatureType memberType)
Method Detail

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>
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>

closeIterator

public void closeIterator(FeatureIterator<SimpleFeature> close)

accepts

public void accepts(FeatureVisitor visitor,
                    ProgressListener progress)
             throws IOException
Accepts a visitor, which then visits each feature in the collection.

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

subList

public FeatureCollection<SimpleFeatureType,SimpleFeature> subList(Filter filter)

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>
Returns:
FeatureCollection identified as subset.
See Also:
FeatureList

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>
Returns:
FeatureCollection sorted in the indicated order

isEmpty

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

contains

public boolean contains(Object o)
Returns true if this collection contains the specified element. .

This implementation iterates over the elements in the collection, checking each element in turn for equality with the specified element.

Specified by:
contains in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Parameters:
o - object to be checked for containment in this collection.
Returns:
true if this collection contains the specified element.
See Also:
Collection.contains(Object)

toArray

public Object[] toArray()
Array of all the elements.

Specified by:
toArray in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Returns:
an array containing all of the elements in this collection.
See Also:
Collection.toArray()

toArray

public Object[] toArray(Object[] a)
Specified by:
toArray in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
See Also:
Collection.toArray(Object[])

add

public boolean add(SimpleFeature o)
Implement to support modification.

Specified by:
add in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Parameters:
o - element whose presence in this collection is to be ensured.
Returns:
true if the collection changed as a result of the call.
Throws:
UnsupportedOperationException - if the add method is not supported by this collection.
NullPointerException - if this collection does not permit null elements, and the specified element is null.
ClassCastException - if the class of the specified element prevents it from being added to this collection.
IllegalArgumentException - if some aspect of this element prevents it from being added to this collection.
See Also:
Collection.add(Object)

remove

public boolean remove(Object o)
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>
Parameters:
o - element to be removed from this collection, if present.
Returns:
true if the collection contained the specified element.
Throws:
UnsupportedOperationException - if the remove method is not supported by this collection.
See Also:
Collection.remove(Object)

containsAll

public boolean containsAll(Collection c)
Returns true if this collection contains all of the elements in the specified collection.

Specified by:
containsAll in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Parameters:
c - collection to be checked for containment in this collection.
Returns:
true if this collection contains all of the elements in the specified collection.
Throws:
NullPointerException - if the specified collection is null.
See Also:
contains(Object)

addAll

public boolean addAll(Collection c)
Adds all of the elements in the specified collection to this collection (optional operation).

Specified by:
addAll in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Parameters:
c - collection whose elements are to be added to this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
UnsupportedOperationException - if this collection does not support the addAll method.
NullPointerException - if the specified collection is null.
See Also:
#add(Object)

addAll

public boolean addAll(FeatureCollection c)
Specified by:
addAll in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
See Also:
FeatureCollection.addAll(Collection)

removeAll

public boolean removeAll(Collection c)
Removes from this collection all of its elements that are contained in the specified collection (optional operation).

Specified by:
removeAll in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Parameters:
c - elements to be removed from this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
UnsupportedOperationException - if the removeAll method is not supported by this collection.
NullPointerException - if the specified collection is null.
See Also:
remove(Object), contains(Object)

retainAll

public boolean retainAll(Collection c)
Retains only the elements in this collection that are contained in the specified collection (optional operation).

Specified by:
retainAll in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Parameters:
c - elements to be retained in this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
UnsupportedOperationException - if the retainAll method is not supported by this Collection.
NullPointerException - if the specified collection is null.
See Also:
remove(Object), contains(Object)

clear

public void clear()
Removes all of the elements from this collection (optional operation).

Specified by:
clear in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Throws:
UnsupportedOperationException - if the clear method is not supported by this collection.
See Also:
Collection.clear()

toString

public String toString()
Returns a string representation of this collection.

Overrides:
toString in class Object
Returns:
a string representation of this collection.

getOpenIterators

public final Set getOpenIterators()
Returns the set of open iterators.


iterator

public final Iterator<SimpleFeature> iterator()
Please implement!

Note: If you return a ResourceIterator, the default implemntation of close( Iterator ) will know what to do.

Specified by:
iterator in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Returns:
Iterator

size

public abstract int size()
Returns the number of elements in this collection.

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

close

public final void close(Iterator close)
Clean up after any resources assocaited with this iteartor in a manner similar to JDO collections.

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 );
 }
 

Specified by:
close in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Parameters:
close -

openIterator

protected abstract Iterator<SimpleFeature> openIterator()
Open an Iterator, we will call close( iterator ).

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

Returns:
Iterator based on resource use

closeIterator

protected abstract void closeIterator(Iterator<SimpleFeature> close)
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.

Parameters:
close - Iterator, will not be null

purge

public void purge()
Close any outstanding resources released by this resources.

This method should be used with great caution, it is however available to allow the use of the ResourceCollection with algorthims that are unaware of the need to close iterators after use.

Example of using a normal Collections utility method:


 Collections.sort( collection );
 collection.purge(); 
 

Specified by:
purge in interface FeatureCollection<SimpleFeatureType,SimpleFeature>

getID

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

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

addListener

public final void addListener(CollectionListener listener)
                       throws NullPointerException
Description copied from interface: FeatureCollection
Adds a listener for collection events.

When this collection is backed by live data the event notification will follow the guidelines outlined by FeatureListner.

Specified by:
addListener in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Parameters:
listener - The listener to add
Throws:
NullPointerException - If the listener is null.

removeListener

public final void removeListener(CollectionListener listener)
                          throws NullPointerException
Description copied from interface: FeatureCollection
Removes a listener for collection events.

Specified by:
removeListener in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Parameters:
listener - The listener to remove
Throws:
NullPointerException - If the listener is null.

getSchema

public SimpleFeatureType getSchema()
Description copied from interface: FeatureCollection
The schema for the child features of this collection.

There is a difference between getFeatureType() and getSchema()represents the LCD FeatureType that best represents the contents of this collection.

The method getSchema() is named for compatability with the geotools 2.0 API. In the Geotools 2.2 time frame we should be able to replace this method with a careful check of getFeatureType() and its attributes.

Specified by:
getSchema in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Returns:
FeatureType describing the "common" schema to all child features of this collection

getBounds

public ReferencedEnvelope getBounds()
Subclasses need to override this.

Specified by:
getBounds in interface FeatureCollection<SimpleFeatureType,SimpleFeature>
Returns:
An Envelope containing the total bounds of this collection.


Copyright © 1996-2010 Geotools. All Rights Reserved.