|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.geotools.feature.DefaultFeatureCollection
A basic implementation of FeatureCollection which use a TreeMap
for
its internal storage.
This should be considered a MemoryFeatureCollection.
Nested Class Summary |
Nested classes inherited from class org.geotools.feature.Feature |
Feature.NULL |
Constructor Summary | |
protected |
DefaultFeatureCollection(java.lang.String id,
FeatureType featureType)
This constructor is protected to discourage direct usage... |
Method Summary | |
void |
accepts(FeatureVisitor visitor,
ProgressListener progress)
Accepts a visitor, which then visits each feature in the collection. |
protected boolean |
add(Feature feature,
boolean fire)
|
boolean |
add(java.lang.Object o)
Ensures that this collection contains the specified element (optional operation). |
boolean |
addAll(java.util.Collection collection)
Adds all of the elements in the specified collection to this collection (optional operation). |
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 close)
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. |
FeatureCollection |
collection()
Convert this set of results to a FeatureCollection. |
boolean |
contains(java.lang.Object o)
Returns true if this collection contains the specified element. |
boolean |
containsAll(java.util.Collection collection)
Test for collection membership. |
FeatureIterator |
features()
Gets a FeatureIterator of this feature collection. |
java.util.Set |
fids()
Optimization time ... grab the fid set so other can quickly test membership during removeAll/retainAll implementations. |
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)
Gets an attribute for this feature at the location specified by xPath. |
java.lang.Object[] |
getAttributes(java.lang.Object[] attributes)
Copy all the attributes of this Feature into the given array. |
com.vividsolutions.jts.geom.Envelope |
getBounds()
Gets the bounding box for the features in this feature collection. |
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()
Gets a reference to the type of this feature collection. |
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. |
FeatureType |
getSchema()
The schema for the child features of this collection. |
boolean |
isEmpty()
Returns true if this collection contains no elements. |
java.util.Iterator |
iterator()
Returns an iterator over the elements in this collection. |
void |
purge()
Close any outstanding resources released by this resources. |
FeatureReader |
reader()
Provides access to the Features, please note that FeatureReader is a blocking api. |
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 collection)
Removes all this collection's elements that are also contained in the specified collection (optional operation). |
void |
removeListener(CollectionListener listener)
Removes a listener for collection events. |
boolean |
retainAll(java.util.Collection collection)
Retains only the elements in this collection that are contained in the specified collection (optional operation). |
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()
Returns the number of elements in this collection. |
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 MemoryFeatureCollection. |
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this collection. |
java.lang.Object[] |
toArray(java.lang.Object[] a)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. |
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 DefaultFeatureCollection(java.lang.String id, FeatureType featureType)
Opportunistic reuse is encouraged, but only for the purposes
of testing or other specialized uses. Normal creation should
occur through org.geotools.core.FeatureCollections.newCollection()
allowing applications to customize any generated collections.
id
- may be null ... feature idMethod Detail |
public 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 com.vividsolutions.jts.geom.Envelope getBounds()
getBounds
in interface FeatureResults
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 removeprotected void fireChange(Feature[] features, int type)
protected void fireChange(Feature feature, int type)
protected void fireChange(java.util.Collection coll, int type)
public boolean add(java.lang.Object o)
Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.
If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.
add
in interface java.util.Collection
o
- element whose presence in this collection is to be ensured.
protected boolean add(Feature feature, boolean fire)
public boolean addAll(java.util.Collection collection)
addAll
in interface java.util.Collection
collection
- elements to be inserted into this collection.
add(Object)
public void clear()
clear
in interface java.util.Collection
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection
o
- element whose presence in this collection is to be tested.
public boolean containsAll(java.util.Collection collection)
containsAll
in interface java.util.Collection
collection
-
public boolean isEmpty()
isEmpty
in interface java.util.Collection
public java.util.Iterator iterator()
iterator
in interface ResourceCollection
public FeatureIterator features()
features
in interface FeatureCollection
public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection
o
- element to be removed from this collection, if present.
public boolean removeAll(java.util.Collection collection)
removeAll
in interface java.util.Collection
collection
- elements to be removed from this collection.
remove(Object)
,
contains(Object)
public boolean retainAll(java.util.Collection collection)
retainAll
in interface java.util.Collection
collection
- elements to be retained in this collection.
remove(Object)
,
contains(Object)
public int size()
size
in interface java.util.Collection
public java.lang.Object[] toArray()
The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
toArray
in interface java.util.Collection
public java.lang.Object[] toArray(java.lang.Object[] a)
If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of this collection only if the caller knows that this collection does not contain any null elements.)
If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
Like the toArray method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs
Suppose l is a List known to contain only strings. The following code can be used to dump the list into a newly allocated array of String:
String[] x = (String[]) v.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to toArray().
toArray
in interface java.util.Collection
a
- the array into which the elements of this collection are to be
stored, if it is big enough; otherwise, a new array of the same
runtime type is allocated for this purpose.
public FeatureType getFeatureType()
FeatureCollection
There are several limitations on the use of FeatureType with respect to a FeatureCollection.
GML 3.x: all FeatureCollections decend from gml:AbstractFeatureCollectionType:
GML 3.x: gml:AbstractFeatureCollectionType decends from gml:BoundedFeatureType:
There is a difference between getFeatureType() and getSchema(), getSchema is named for historical reasons and reprensets the LCD FeatureType that best represents the contents of this collection.
getFeatureType
in interface FeatureCollection
public FeatureCollection getParent()
Feature
getParent
in interface Feature
public void setParent(FeatureCollection collection)
Feature
setParent
in interface Feature
collection
- the collection to be set as parent.public java.lang.String getID()
Feature
getID
in interface 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)
Feature
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 close(FeatureIterator close)
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 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
- public FeatureReader reader() throws java.io.IOException
FeatureResults
reader
in interface FeatureResults
java.io.IOException
- DOCUMENT ME!public 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 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 Featurespublic java.util.Set fids()
public void accepts(FeatureVisitor visitor, ProgressListener progress) throws java.io.IOException
accepts
in interface FeatureCollection
visitor
-
java.io.IOException
public FeatureCollection subCollection(Filter filter)
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
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
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |