org.geotools.data.collection
Class ListFeatureCollection

Object
  extended by AbstractFeatureCollection
      extended by ListFeatureCollection
All Implemented Interfaces:
Iterable<SimpleFeature>, Collection<SimpleFeature>, SimpleFeatureCollection, FeatureCollection<SimpleFeatureType,SimpleFeature>

public class ListFeatureCollection
extends AbstractFeatureCollection
implements Collection<SimpleFeature>

FeatureCollection implementation wrapping around a java.util.List.

This implementation wraps around a java.util.List and is suitable for quickly getting something on screen.

Usage notes:

This implementation is intended to quickly wrap up a list of features and get them on screen; as such it respects various hints about the copying of internal content as provided by the renderer.

Author:
Oliver Gottwald, Jody
See Also:
Hints#FEATURE_DETACHED

Field Summary
 
Fields inherited from class AbstractFeatureCollection
id, schema
 
Constructor Summary
ListFeatureCollection(SimpleFeatureCollection copy)
          Create a ListFeatureCollection around the provided list.
ListFeatureCollection(SimpleFeatureType schema)
          Create a ListFeatureCollection for the provided schema An ArrayList is used internally.
ListFeatureCollection(SimpleFeatureType schema, List<SimpleFeature> list)
          Create a ListFeatureCollection around the provided list.
 
Method Summary
 boolean add(SimpleFeature f)
           
 boolean addAll(Collection<? extends SimpleFeature> c)
           
 void clear()
           
 SimpleFeatureIterator features()
          Obtain a SimpleFeatureIterator of the Features within this SimpleFeatureCollection.
 ReferencedEnvelope getBounds()
          Subclasses need to override this.
 boolean isEmpty()
          Returns true if this feature collection contains no features.
protected  Iterator<SimpleFeature> openIterator()
          Factory method used to open an iterator over collection contents for use by AbstractFeatureCollection.iterator() and AbstractFeatureCollection.features().
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
 int size()
          Returns the number of elements in this collection.
 SimpleFeatureCollection sort(SortBy order)
          Obtained sorted contents.
 SimpleFeatureCollection subCollection(Filter filter)
          SimpleFeatureCollection "view" indicated by provided filter.
 
Methods inherited from class AbstractFeatureCollection
accepts, contains, containsAll, getID, getSchema, iterator, toArray, toArray
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface Collection
contains, containsAll, equals, hashCode, iterator, toArray, toArray
 

Constructor Detail

ListFeatureCollection

public ListFeatureCollection(SimpleFeatureType schema)
Create a ListFeatureCollection for the provided schema An ArrayList is used internally.

Parameters:
schema -

ListFeatureCollection

public ListFeatureCollection(SimpleFeatureType schema,
                             List<SimpleFeature> list)
Create a ListFeatureCollection around the provided list. The contents of the list should all be of the provided schema for this to make sense. Please keep in mind the feature collection control, no two Features in the list should have the same feature id, and you should not insert the same feature more then once.

The provided list is directly used for storage, most feature collection operations just use a simple iterator so there is no performance advantaged to be gained over using an ArrayList vs a LinkedList (other then for the size() method of course).

Parameters:
schema -
list -

ListFeatureCollection

public ListFeatureCollection(SimpleFeatureCollection copy)
                      throws IOException
Create a ListFeatureCollection around the provided list. The contents of the list should all be of the provided schema for this to make sense. Please keep in mind the feature collection control, no two Features in the list should have the same feature id, and you should not insert the same feature more then once.

The provided list is directly used for storage, most feature collection operations just use a simple iterator so there is no performance advantaged to be gained over using an ArrayList vs a LinkedList (other then for the size() method of course).

Parameters:
schema -
list -
Throws:
IOException
Method Detail

size

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

Specified by:
size in interface Collection<SimpleFeature>
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()

openIterator

protected Iterator<SimpleFeature> openIterator()
Description copied from class: AbstractFeatureCollection
Factory method used to open an iterator over collection contents for use by AbstractFeatureCollection.iterator() and AbstractFeatureCollection.features().

If you return an instance of FeatureIterator some effort is taken to call the FeatureIterator.close() internally, however we cannot offer any assurance that client code using AbstractFeatureCollection.iterator() will perform the same check.

Specified by:
openIterator in class AbstractFeatureCollection
Returns:
Iterator over collection contents

add

public boolean add(SimpleFeature f)
Specified by:
add in interface Collection<SimpleFeature>

clear

public void clear()
Specified by:
clear in interface Collection<SimpleFeature>

features

public SimpleFeatureIterator features()
Description copied from interface: SimpleFeatureCollection
Obtain a SimpleFeatureIterator of the Features within this SimpleFeatureCollection.

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

Example use:


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

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

getBounds

public ReferencedEnvelope getBounds()
Description copied from class: AbstractFeatureCollection
Subclasses need to override this.

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

isEmpty

public boolean isEmpty()
Description copied from interface: FeatureCollection
Returns true if this feature collection contains no features.

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

subCollection

public SimpleFeatureCollection subCollection(Filter filter)
Description copied from interface: FeatureCollection
SimpleFeatureCollection "view" indicated by provided filter.

The contents of the returned SimpleFeatureCollection 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 SimpleFeatureCollection 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:

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

sort

public SimpleFeatureCollection sort(SortBy order)
Description copied from interface: FeatureCollection
Obtained sorted contents.

This method may not be supported by all implementations, consider the use of FeatureSource.features( Query ).

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

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<SimpleFeature>

addAll

public boolean addAll(Collection<? extends SimpleFeature> c)
Specified by:
addAll in interface Collection<SimpleFeature>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<SimpleFeature>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<SimpleFeature>


Copyright © 1996-2014 Geotools. All Rights Reserved.