org.geotools.feature.collection
Class AbstractFeatureCollection

java.lang.Object
  extended by org.geotools.feature.collection.AbstractFeatureCollection
All Implemented Interfaces:
FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Direct Known Subclasses:
ForceCoordinateSystemFeatureResults, MemoryFeatureCollection, ReprojectFeatureResults, SubFeatureCollection

public abstract class AbstractFeatureCollection
extends java.lang.Object
implements FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>

Implement a feature collection just based on provision of iterator.

Author:
Jody Garnett (Refractions Research Inc)

Field Summary
protected  java.lang.String id
          id used when serialized to gml
protected  java.util.List listeners
          listeners
protected  java.util.Set open
          Set of open resource iterators
protected  org.opengis.feature.simple.SimpleFeatureType schema
           
 
Constructor Summary
protected AbstractFeatureCollection(org.opengis.feature.simple.SimpleFeatureType memberType)
           
 
Method Summary
 void accepts(org.opengis.feature.FeatureVisitor visitor, org.opengis.util.ProgressListener progress)
          Visit the contents of a feature collection.
 void accepts(FeatureVisitor visitor, ProgressListener progress)
           
 boolean add(org.opengis.feature.simple.SimpleFeature o)
          Implement to support modification.
 boolean addAll(java.util.Collection<? extends org.opengis.feature.simple.SimpleFeature> c)
          Adds all of the elements in the specified collection to this collection (optional operation).
 boolean addAll(FeatureCollection<? extends org.opengis.feature.simple.SimpleFeatureType,? extends org.opengis.feature.simple.SimpleFeature> 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<org.opengis.feature.simple.SimpleFeature> close)
          Clean up after any resources associated with this FeatureIterator in a manner similar to JDO collections.
 void close(java.util.Iterator close)
          Clean up after any resources associated with this iteartor in a manner similar to JDO collections.
protected abstract  void closeIterator(java.util.Iterator close)
          Please override to cleanup after your own iterators, and any used resources.
 boolean contains(java.lang.Object o)
          Returns true if this collection contains the specified element.
 boolean containsAll(java.util.Collection<?> c)
          Returns true if this collection contains all of the elements in the specified collection.
 FeatureIterator<org.opengis.feature.simple.SimpleFeature> features()
          Obtain a FeatureIterator of the Features within this collection.
 ReferencedEnvelope getBounds()
          Subclasses need to override this.
 java.lang.String getID()
          ID used when serializing to GML
 java.util.Set getOpenIterators()
          Returns the set of open iterators.
 org.opengis.feature.simple.SimpleFeatureType getSchema()
          The schema for the child features of this collection.
 boolean isEmpty()
           
 java.util.Iterator iterator()
          Please implement!
protected abstract  java.util.Iterator openIterator()
          Open a resource based Iterator, we will call close( iterator ).
 void purge()
          Close any outstanding resources released by this resources.
 boolean remove(java.lang.Object o)
          Removes a single instance of the specified element from this collection, if it is present (optional operation).
 boolean removeAll(java.util.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(java.util.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> sort(org.opengis.filter.sort.SortBy order)
          collection.subCollection( myFilter ).sort( {"foo","bar"} ); collection.subCollection( myFilter ).sort( "bar" ).sort("foo")
 FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> subCollection(org.opengis.filter.Filter filter)
          FeatureCollection "view" indicated by provided filter.
 FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> subList(org.opengis.filter.Filter filter)
           
 java.lang.Object[] toArray()
          Array of all the elements.
<T> T[]
toArray(T[] a)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

protected java.util.List listeners
listeners


id

protected java.lang.String id
id used when serialized to gml


schema

protected org.opengis.feature.simple.SimpleFeatureType schema

open

protected final java.util.Set open
Set of open resource iterators

Constructor Detail

AbstractFeatureCollection

protected AbstractFeatureCollection(org.opengis.feature.simple.SimpleFeatureType memberType)
Method Detail

features

public FeatureIterator<org.opengis.feature.simple.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Returns:
A FeatureIterator.

close

public final void close(java.util.Iterator close)
Clean up after any resources associated 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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Parameters:
close -

close

public void close(FeatureIterator<org.opengis.feature.simple.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>

openIterator

protected abstract java.util.Iterator openIterator()
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().

Returns:
Iterator based on resource use

closeIterator

protected abstract void closeIterator(java.util.Iterator 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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>

size

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

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

add

public boolean add(org.opengis.feature.simple.SimpleFeature o)
Implement to support modification.

Specified by:
add in interface FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.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:
java.lang.UnsupportedOperationException - if the add method is not supported by this collection.
java.lang.NullPointerException - if this collection does not permit null elements, and the specified element is null.
java.lang.ClassCastException - if the class of the specified element prevents it from being added to this collection.
java.lang.IllegalArgumentException - if some aspect of this element prevents it from being added to this collection.
See Also:
Collection.add(Object)

addAll

public boolean addAll(java.util.Collection<? extends org.opengis.feature.simple.SimpleFeature> c)
Adds all of the elements in the specified collection to this collection (optional operation).

Specified by:
addAll in interface FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.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:
java.lang.UnsupportedOperationException - if this collection does not support the addAll method.
java.lang.NullPointerException - if the specified collection is null.
See Also:
#add(Object)

addAll

public boolean addAll(FeatureCollection<? extends org.opengis.feature.simple.SimpleFeatureType,? extends org.opengis.feature.simple.SimpleFeature> c)
Specified by:
addAll in interface FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
See Also:
FeatureCollection.addAll(Collection)

clear

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

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

contains

public boolean contains(java.lang.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.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)

containsAll

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

Specified by:
containsAll in interface FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.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:
java.lang.NullPointerException - if the specified collection is null.
See Also:
contains(Object)

getOpenIterators

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


iterator

public final java.util.Iterator 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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Returns:
Iterator

isEmpty

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

remove

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

removeAll

public final boolean removeAll(java.util.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Parameters:
c - elements to be removed from this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
java.lang.UnsupportedOperationException - if the removeAll method is not supported by this collection.
java.lang.NullPointerException - if the specified collection is null.
See Also:
remove(Object), contains(Object)

retainAll

public final boolean retainAll(java.util.Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection (optional operation).

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

toArray

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

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

toArray

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

accepts

public void accepts(org.opengis.feature.FeatureVisitor visitor,
                    org.opengis.util.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Parameters:
visitor - Closure applied to each feature in turn.
progress - Used to report progress, may be used to interrupt the operation

subList

public FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> subList(org.opengis.filter.Filter filter)

subCollection

public FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> subCollection(org.opengis.filter.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Returns:
FeatureCollection identified as subset.
See Also:
FeatureList

sort

public FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> sort(org.opengis.filter.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Returns:
FeatureCollection sorted in the indicated order

getID

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

Specified by:
getID in interface FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>

addListener

public final void addListener(CollectionListener listener)
                       throws java.lang.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Parameters:
listener - The listener to add
Throws:
java.lang.NullPointerException - If the listener is null.

removeListener

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

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

accepts

public final void accepts(FeatureVisitor visitor,
                          ProgressListener progress)
                   throws java.io.IOException
Throws:
java.io.IOException

getSchema

public org.opengis.feature.simple.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Returns:
An Envelope containing the total bounds of this collection.


Copyright © 1996-2010 Geotools. All Rights Reserved.