|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.geotools.data.store.DataFeatureCollection
A starting point for implementing FeatureCollection's backed by real data.
The API you are required to implement is *identical* the the barebones FeatureResults interface:
This class will implement the 'extra' methods required by FeatureCollection for you (in simple terms based on the FeatureResults API). Anything that is often customized is available to you as a constructor parameters.
Enjoy.
Nested Class Summary |
Nested classes inherited from class org.geotools.feature.Feature |
Feature.NULL |
Constructor Summary | |
protected |
DataFeatureCollection()
Collection based on a generic collection |
protected |
DataFeatureCollection(java.lang.String id)
Collection based on a generic collection |
protected |
DataFeatureCollection(java.lang.String id,
FeatureType featureType)
Subclass must think about what consitructors it needs. |
Method Summary | |
void |
accepts(FeatureVisitor visitor,
ProgressListener progress)
Accepts a visitor, which then visits each feature in the collection. |
boolean |
add(java.lang.Object arg0)
|
boolean |
addAll(java.util.Collection arg0)
Optimized implementation of addAll that recognizes the use of collections obtained with subCollection( filter ). |
void |
addListener(CollectionListener listener)
Adds a listener for collection events. |
void |
clear()
|
void |
close(FeatureIterator iterator)
Clean up any resources assocaited with this iterator in a manner similar to JDO collections. |
void |
close(java.util.Iterator close)
Clean up after any resources assocaited with this itterator in a manner similar to JDO collections. |
protected void |
closeIterator(java.util.Iterator close)
|
abstract FeatureCollection |
collection()
Convert this set of results to a FeatureCollection. |
boolean |
contains(java.lang.Object o)
|
boolean |
containsAll(java.util.Collection arg0)
|
FeatureIterator |
features()
FeatureIterator is entirely based on iterator(). |
protected void |
fireChange(java.util.Collection coll,
int type)
|
protected void |
fireChange(Feature[] features,
int type)
To let listeners know that something has changed. |
protected void |
fireChange(Feature feature,
int type)
|
java.lang.Object |
getAttribute(int index)
Gets an attribute by the given zero-based index. |
java.lang.Object |
getAttribute(java.lang.String xPath)
Not really interested yet .. |
java.lang.Object[] |
getAttributes(java.lang.Object[] attributes)
Copy all the attributes of this Feature into the given array. |
abstract com.vividsolutions.jts.geom.Envelope |
getBounds()
Returns the bounding box of this FeatureResults. |
abstract int |
getCount()
Returns the number of Features in this FeatureResults. |
com.vividsolutions.jts.geom.Geometry |
getDefaultGeometry()
Gets the default geometry for this feature. |
FeatureType |
getFeatureType()
FeatureType of this FeatureCollection. |
java.lang.String |
getID()
Gets the unique feature ID for this feature. |
int |
getNumberOfAttributes()
Get the number of attributes this feature has. |
FeatureCollection |
getParent()
Gets the feature collection this feature is stored in. |
abstract FeatureType |
getSchema()
The schema for the child features of this collection. |
boolean |
isEmpty()
Default implementation based on creating an reader, testing hasNext, and closing. |
java.util.Iterator |
iterator()
Iterator may (or may) not support modification. |
protected java.util.Iterator |
openIteartor()
Returns a FeatureWriterIterator, or FeatureReaderIterator over content. |
void |
purge()
Close any outstanding resources released by this resources. |
abstract FeatureReader |
reader()
Provides access to the Features, please note that FeatureReader is a blocking api. |
boolean |
remove(java.lang.Object arg0)
|
boolean |
removeAll(java.util.Collection arg0)
|
void |
removeListener(CollectionListener listener)
Removes a listener for collection events. |
boolean |
retainAll(java.util.Collection arg0)
|
void |
setAttribute(int position,
java.lang.Object val)
Sets an attribute by the given zero-based index. |
void |
setAttribute(java.lang.String xPath,
java.lang.Object attribute)
Sets a single attribute for this feature, passed as a complex object. |
void |
setDefaultGeometry(com.vividsolutions.jts.geom.Geometry geometry)
Sets the default geometry for this feature. |
void |
setParent(FeatureCollection collection)
Sets the parent collection this feature is stored in, if it is not already set. |
int |
size()
Default implementation based on getCount() - this may be expensive |
FeatureList |
sort(SortBy order)
Construct a sorted view of this content. |
FeatureList |
sort(SortBy2 order)
Allows for "Advanced" sort capabilities specific to the GeoTools platform! |
FeatureCollection |
subCollection(Filter filter)
Will return an optimized subCollection based on access to the origional FeatureSource. |
java.lang.Object[] |
toArray()
|
java.lang.Object[] |
toArray(java.lang.Object[] arg0)
|
protected FeatureWriter |
writer()
Subclass may provide an implementation of this method to indicate that read/write support is provided. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Collection |
equals, hashCode |
Constructor Detail |
protected DataFeatureCollection()
protected DataFeatureCollection(java.lang.String id)
protected DataFeatureCollection(java.lang.String id, FeatureType featureType)
Method Detail |
protected void fireChange(Feature[] features, int type)
protected void fireChange(Feature feature, int type)
protected void fireChange(java.util.Collection coll, int type)
public abstract FeatureType getSchema()
FeatureCollection
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.
getSchema
in interface FeatureCollection
public abstract FeatureReader reader() throws java.io.IOException
FeatureResults
reader
in interface FeatureResults
java.io.IOException
- DOCUMENT ME!public abstract com.vividsolutions.jts.geom.Envelope getBounds()
FeatureResults
This opperation may be expensive. Consider
FeatureSource.getBounds( Query )
as an alternative.
public Envelope getBounds() throws IOException {
Envelope newBBox = new Envelope();
Envelope internal;
Feature feature;
for (FeatureReader r = reader(); r.hasNext();) {
feature = r.next();
internal = feature.getDefaultGeometry().getEnvelopeInternal();
newBBox.expandToInclude(internal);
}
return newBBox;
}
getBounds
in interface FeatureResults
public abstract int getCount() throws java.io.IOException
FeatureResults
This opperation may be expensive. Consider FeatureSource.getCount(
Query )
as an alternative.
public int getCount() throws IOException {
int count = 0;
for (FeatureReader r = reader(); r.hasNext(); count++) {
r.next();
}
return count;
}
getCount
in interface FeatureResults
java.io.IOException
- If there are problems getting the countpublic abstract FeatureCollection collection() throws java.io.IOException
FeatureResults
This method is logically the same as:
public FeatureCollection collection() throws IOException {
FeatureCollection collection = FeatureCollections.newCollection()
for (FeatureReader r = reader(); r.hasNext();) {
collection.add( r.next() );
}
return collection;
}
collection
in interface FeatureResults
java.io.IOException
- If any problems occur aquiring Featuresprotected FeatureWriter writer() throws java.io.IOException
All operations that attempt to modify the "data" will use this method, allowing them to throw an "UnsupportedOperationException" in the same manner as Collections.unmodifiableCollection(Collection c)
java.lang.UnsupportedOperationException
- To indicate that write support is not avaiable
java.io.IOException
public void addListener(CollectionListener listener)
addListener
in interface FeatureCollection
listener
- The listener to addpublic void removeListener(CollectionListener listener)
removeListener
in interface FeatureCollection
listener
- The listener to removepublic FeatureIterator features()
So when we implement FeatureCollection.iterator() this will work out of the box.
features
in interface FeatureCollection
public final java.util.Iterator iterator()
iterator
in interface ResourceCollection
protected java.util.Iterator openIteartor()
If you have a way to tell that you are readonly please subclass with a less hardcore check - this implementations catches a UnsupportedOpperationsException from wrtier()!
public void close(FeatureIterator iterator)
FeatureCollection
You must be sure to allow null values, this is because in a try/finally block client code may not be sure if they have actualy succeed in assign a value to an iterator they wish to ensure is closed. By permiting null as an api we prevent a null check in lots of finally statements.
Note: Because of FeatureReader using an interator internally, there is only one implementation of this method that makes any sense:
public void close( FeatureIterator iterator) {
if( iterator != null ) iterator.close();
}
close
in interface FeatureCollection
public final void close(java.util.Iterator close)
FeatureCollection
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 );
}
close
in interface FeatureCollection
close
- protected void closeIterator(java.util.Iterator close)
public int size()
size
in interface java.util.Collection
public void purge()
ResourceCollection
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();
purge
in interface ResourceCollection
public boolean isEmpty()
For once the Collections API does not give us an escape route, we *have* to check the data.
isEmpty
in interface java.util.Collection
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection
public java.lang.Object[] toArray(java.lang.Object[] arg0)
toArray
in interface java.util.Collection
public boolean add(java.lang.Object arg0)
add
in interface java.util.Collection
public boolean remove(java.lang.Object arg0)
remove
in interface java.util.Collection
public boolean containsAll(java.util.Collection arg0)
containsAll
in interface java.util.Collection
public boolean addAll(java.util.Collection arg0)
This method is constructed by either:
addAll
in interface java.util.Collection
public boolean removeAll(java.util.Collection arg0)
removeAll
in interface java.util.Collection
public boolean retainAll(java.util.Collection arg0)
retainAll
in interface java.util.Collection
public void clear()
clear
in interface java.util.Collection
public FeatureType getFeatureType()
Unless a FeatureType was provided during consturction (or this method is overriden) a FeatureType will be generated based on getSchmea according to the following assumptions:
getFeatureType
in interface FeatureCollection
public FeatureCollection getParent()
Feature
public void setParent(FeatureCollection collection)
Feature
collection
- the collection to be set as parent.public java.lang.String getID()
Feature
public java.lang.Object[] getAttributes(java.lang.Object[] attributes)
Feature
getAttributes
in interface Feature
attributes
- An array to copy attributes into. May be null.
public java.lang.Object getAttribute(java.lang.String xPath)
getAttribute
in interface Feature
xPath
- XPath representation of attribute location.
public java.lang.Object getAttribute(int index)
Feature
getAttribute
in interface Feature
index
- The requested index. Must be 0 <= idx <
getNumberOfAttributes().
Feature.getAttribute(String)
public void setAttribute(int position, java.lang.Object val) throws IllegalAttributeException, java.lang.ArrayIndexOutOfBoundsException
Feature
setAttribute
in interface Feature
position
- The requested index. Must be 0 <= idx <
getNumberOfAttributes()val
- An object representing the attribute being set
java.lang.ArrayIndexOutOfBoundsException
- if an invalid position is given
IllegalAttributeException
- if the passed in val does not validate
against the AttributeType at that position.Feature.setAttribute(String, Object)
public int getNumberOfAttributes()
Feature
getNumberOfAttributes
in interface Feature
public void setAttribute(java.lang.String xPath, java.lang.Object attribute) throws IllegalAttributeException
Feature
setAttribute
in interface Feature
xPath
- XPath representation of attribute location.attribute
- Feature attribute to set.
IllegalAttributeException
- If the attribute is illegal for the
path specified.public com.vividsolutions.jts.geom.Geometry getDefaultGeometry()
Feature
This method will return null
if no DefaultGeometry has been
defined by the schema.
getDefaultGeometry
in interface Feature
null
public void setDefaultGeometry(com.vividsolutions.jts.geom.Geometry geometry) throws IllegalAttributeException
Feature
setDefaultGeometry
in interface Feature
geometry
- The geometry to set.
IllegalAttributeException
- If the AttributeType is not a
geometry, or is invalid for some other reason.public void accepts(FeatureVisitor visitor, ProgressListener progress) throws java.io.IOException
accepts
in interface FeatureCollection
visitor
-
java.io.IOException
public FeatureCollection subCollection(Filter filter)
The subCollection is constructed by using an AND Filter. For the converse of this opperation please see collection.addAll( Collection ), it has been optimized to be aware of these filter based SubCollections.
This method is intended in a manner similar to subList,
example use:
collection.subCollection( myFilter ).clear()
subCollection
in interface FeatureCollection
filter
- Filter used to determine sub collection.
FeatureList
public FeatureList sort(SortBy order)
Sorts may be combined togther in a stable fashion, in congruence with the Filter 1.1 specification.
This method should also be able to handle GeoTools specific sorting through detecting order as a SortBy2 instance.
sort
in interface FeatureCollection
order
- Filter 1.1 SortBy
public FeatureList sort(SortBy2 order)
Advanced in this case really means making use of a generic Expression, rather then being limited to PropertyName.
order
- GeoTools SortBy
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |