org.geotools.data.memory
Class MemoryFeatureCollection

java.lang.Object
  extended byorg.geotools.feature.collection.AbstractResourceCollection
      extended byorg.geotools.feature.collection.AbstractFeatureCollection
          extended byorg.geotools.data.memory.MemoryFeatureCollection
All Implemented Interfaces:
java.util.Collection, Feature, FeatureCollection, FeatureResults, RandomFeatureAccess, ResourceCollection

public class MemoryFeatureCollection
extends AbstractFeatureCollection
implements RandomFeatureAccess

Implement a FeatureCollection by burning memory!

Contents are maintained in a sorted TreeMap by FID, this serves as a reference implementation when exploring the FeatureCollection api.

This is similar to DefaultFeatureCollection, although additional methods are supported and test cases have been written. Unlike DefaultFeatureCollection the type information must be known at construction time.

Author:
Jody Garnett, Refractions Research

Nested Class Summary
 
Nested classes inherited from class org.geotools.feature.Feature
Feature.NULL
 
Field Summary
 
Fields inherited from class org.geotools.feature.collection.AbstractResourceCollection
open
 
Constructor Summary
MemoryFeatureCollection(FeatureType schema)
           
 
Method Summary
 boolean add(java.lang.Object o)
          Implement to support modification.
protected  void closeIterator(java.util.Iterator close)
          Please override to cleanup after your own iterators, and any used resources.
 Feature getFeatureMember(java.lang.String id)
          Access Feature content by feature id.
protected  java.util.Iterator openIterator()
          Open a resource based Iterator, we will call close( iterator ).
 Feature removeFeatureMember(java.lang.String id)
          Optional Method
 int size()
          Returns the number of elements in this collection.
 
Methods inherited from class org.geotools.feature.collection.AbstractFeatureCollection
accepts, addListener, close, closeIterator, collection, features, getAttribute, getAttribute, getAttributes, getBounds, getCount, getDefaultGeometry, getFeatureType, getID, getNumberOfAttributes, getParent, getSchema, purge, reader, removeListener, setAttribute, setAttribute, setDefaultGeometry, setParent, sort, subCollection, subList
 
Methods inherited from class org.geotools.feature.collection.AbstractResourceCollection
addAll, clear, close, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.geotools.feature.FeatureCollection
accepts, addListener, close, close, features, getFeatureType, getSchema, removeListener, sort, subCollection
 
Methods inherited from interface org.geotools.data.collection.ResourceCollection
iterator, purge
 
Methods inherited from interface java.util.Collection
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from interface org.geotools.data.FeatureResults
collection, getBounds, getCount, reader
 
Methods inherited from interface org.geotools.feature.Feature
getAttribute, getAttribute, getAttributes, getBounds, getDefaultGeometry, getID, getNumberOfAttributes, getParent, setAttribute, setAttribute, setDefaultGeometry, setParent
 

Constructor Detail

MemoryFeatureCollection

public MemoryFeatureCollection(FeatureType schema)
Method Detail

size

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

Specified by:
size in interface java.util.Collection
Specified by:
size in class AbstractResourceCollection
Returns:
Number of items, or Interger.MAX_VALUE

openIterator

protected java.util.Iterator openIterator()
Description copied from class: AbstractResourceCollection
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 AbstractResourceCollection
Returns:
Iterator based on resource use

closeIterator

protected void closeIterator(java.util.Iterator close)
Description copied from class: AbstractResourceCollection
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 AbstractResourceCollection
Parameters:
close - Iterator, will not be null

add

public boolean add(java.lang.Object o)
Description copied from class: AbstractResourceCollection
Implement to support modification.

Specified by:
add in interface java.util.Collection
Overrides:
add in class AbstractResourceCollection
Parameters:
o - element whose presence in this collection is to be ensured.
Returns:
true if the collection changed as a result of the call.

getFeatureMember

public Feature getFeatureMember(java.lang.String id)
                         throws java.util.NoSuchElementException
Description copied from interface: RandomFeatureAccess
Access Feature content by feature id.

Specified by:
getFeatureMember in interface RandomFeatureAccess
Parameters:
id -
Returns:
Feature with the indicated or id
Throws:
java.util.NoSuchElementException - if a Feature with the indicated id is not present

removeFeatureMember

public Feature removeFeatureMember(java.lang.String id)
Description copied from interface: RandomFeatureAccess
Optional Method

Specified by:
removeFeatureMember in interface RandomFeatureAccess


Copyright © GeoTools. All Rights Reserved.