org.geotools.data.store
Class FilteringFeatureCollection<T extends FeatureType,F extends Feature>

Object
  extended by DecoratingFeatureCollection<T,F>
      extended by FilteringFeatureCollection<T,F>
All Implemented Interfaces:
FeatureCollection<T,F>

public class FilteringFeatureCollection<T extends FeatureType,F extends Feature>
extends DecoratingFeatureCollection<T,F>

Decorates a feature collection with one that filters content.

Author:
Justin Deoliveira, The Open Planning Project
Module:
modules/library/main (gt-main.jar)

Constructor Summary
FilteringFeatureCollection(FeatureCollection<T,F> delegate, Filter filter)
           
 
Method Summary
 boolean add(F o)
          Add object to this collection.
 boolean addAll(Collection c)
          Add all the objects to the collection.
 void close(FeatureIterator<F> close)
          Clean up after any resources associated with this FeatureIterator in a manner similar to JDO collections.
 void close(Iterator<F> close)
          Clean up after any resources associated with this itterator in a manner similar to JDO collections.
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
 FeatureIterator<F> features()
          Obtain a FeatureIterator of the Features within this collection.
 ReferencedEnvelope getBounds()
          Get the total bounds of this collection which is calculated by doing a union of the bounds of each feature inside of it
 boolean isEmpty()
           
 Iterator<F> iterator()
          An iterator over this collection, which must be closed after use.
 FeatureReader<T,F> reader()
           
 int size()
           
 FeatureCollection<T,F> sort(SortBy order)
          collection.subCollection( myFilter ).sort( {"foo","bar"} ); collection.subCollection( myFilter ).sort( "bar" ).sort("foo")
 FeatureCollection<T,F> subCollection(Filter filter)
          FeatureCollection "view" indicated by provided filter.
 Object[] toArray()
           
 Object[] toArray(Object[] a)
           
 
Methods inherited from class DecoratingFeatureCollection
accepts, accepts, addAll, addListener, clear, equals, getID, getSchema, hashCode, purge, remove, removeAll, removeListener, retainAll
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilteringFeatureCollection

public FilteringFeatureCollection(FeatureCollection<T,F> delegate,
                                  Filter filter)
Method Detail

features

public FeatureIterator<F> 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<T extends FeatureType,F extends Feature>
Overrides:
features in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>
Returns:
A FeatureIterator.

close

public void close(FeatureIterator<F> 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<T extends FeatureType,F extends Feature>
Overrides:
close in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>

iterator

public Iterator<F> iterator()
Description copied from interface: FeatureCollection
An iterator over this collection, which must be closed after use.

Collection is not guaranteed to be ordered in any manner.

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.

Example (safe) use:

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

Specified by:
iterator in interface FeatureCollection<T extends FeatureType,F extends Feature>
Overrides:
iterator in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>
Returns:
Iterator

close

public void close(Iterator<F> close)
Description copied from interface: FeatureCollection
Clean up after any resources associated with this itterator 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<T extends FeatureType,F extends Feature>
Overrides:
close in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>

subCollection

public FeatureCollection<T,F> 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<T extends FeatureType,F extends Feature>
Overrides:
subCollection in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>
Returns:
FeatureCollection identified as subset.
See Also:
FeatureList

sort

public FeatureCollection<T,F> 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<T extends FeatureType,F extends Feature>
Overrides:
sort in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>
Returns:
FeatureCollection sorted in the indicated order

size

public int size()
Specified by:
size in interface FeatureCollection<T extends FeatureType,F extends Feature>
Overrides:
size in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>
See Also:
Collection.size()

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface FeatureCollection<T extends FeatureType,F extends Feature>
Overrides:
isEmpty in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>
See Also:
Collection.isEmpty()

toArray

public Object[] toArray()
Specified by:
toArray in interface FeatureCollection<T extends FeatureType,F extends Feature>
Overrides:
toArray in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>
See Also:
Collection.toArray()

toArray

public Object[] toArray(Object[] a)
Specified by:
toArray in interface FeatureCollection<T extends FeatureType,F extends Feature>
Overrides:
toArray in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>
See Also:
Collection.toArray(Object[])

add

public boolean add(F o)
Description copied from interface: FeatureCollection
Add object to this collection.

This method is often not impelmented for collections produced as the result of a query.

Specified by:
add in interface FeatureCollection<T extends FeatureType,F extends Feature>
Overrides:
add in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>
Returns:
true of the element was added
See Also:
Collection.add(Object)

contains

public boolean contains(Object o)
Specified by:
contains in interface FeatureCollection<T extends FeatureType,F extends Feature>
Overrides:
contains in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>
See Also:
Collection.contains(Object)

addAll

public boolean addAll(Collection c)
Description copied from interface: FeatureCollection
Add all the objects to the collection.

This method is often not implemented for collections produced as the results of a query.

Specified by:
addAll in interface FeatureCollection<T extends FeatureType,F extends Feature>
Overrides:
addAll in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>
See Also:
Collection.addAll(Collection)

containsAll

public boolean containsAll(Collection c)
Specified by:
containsAll in interface FeatureCollection<T extends FeatureType,F extends Feature>
Overrides:
containsAll in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>
See Also:
Collection.containsAll(Collection)

reader

public FeatureReader<T,F> reader()
                                                              throws IOException
Throws:
IOException

getBounds

public ReferencedEnvelope getBounds()
Description copied from interface: FeatureCollection
Get the total bounds of this collection which is calculated by doing a union of the bounds of each feature inside of it

Specified by:
getBounds in interface FeatureCollection<T extends FeatureType,F extends Feature>
Overrides:
getBounds in class DecoratingFeatureCollection<T extends FeatureType,F extends Feature>
Returns:
An Envelope containing the total bounds of this collection.


Copyright © 1996-2010 Geotools. All Rights Reserved.