Class ListFeatureCollection
- Object
-
- AbstractFeatureCollection
-
- 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 does not use a spatial index, please do not expect spatial operations to be fast.
- FeatureCollections are not allowed to have duplicates
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 Modifier and Type Field Description protected ReferencedEnvelope
bounds
Cached boundsprotected List<SimpleFeature>
list
wrapped list of features containing the contents-
Fields inherited from class AbstractFeatureCollection
id, schema
-
-
Constructor Summary
Constructors Constructor Description 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.ListFeatureCollection(SimpleFeatureType schema, SimpleFeature... array)
Create a ListFeatureCollection around the provided array.ListFeatureCollection(SimpleFeatureCollection copy)
Create a ListFeatureCollection around the provided list.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(SimpleFeature f)
boolean
addAll(Collection<? extends SimpleFeature> c)
protected ReferencedEnvelope
calculateBounds()
Calculate bounds from featuresvoid
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 byAbstractFeatureCollection.iterator()
andAbstractFeatureCollection.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, parallelStream, removeIf, spliterator, stream, toArray, toArray, toArray
-
-
-
-
Field Detail
-
list
protected List<SimpleFeature> list
wrapped list of features containing the contents
-
bounds
protected ReferencedEnvelope bounds
Cached bounds
-
-
Constructor Detail
-
ListFeatureCollection
public ListFeatureCollection(SimpleFeatureType schema)
Create a ListFeatureCollection for the provided schema An ArrayList is used internally.
-
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 constraints, 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).
-
ListFeatureCollection
public ListFeatureCollection(SimpleFeatureType schema, SimpleFeature... array)
Create a ListFeatureCollection around the provided array. The contents of the array should all be of the provided schema for this to make sense. Please keep in mind the feature collection constraints, 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 array is directly used with a
CopyOnWriteArrayList
for storage.
-
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).
- 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 interfaceCollection<SimpleFeature>
- Specified by:
size
in interfaceFeatureCollection<SimpleFeatureType,SimpleFeature>
- Specified by:
size
in classAbstractFeatureCollection
- 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 byAbstractFeatureCollection.iterator()
andAbstractFeatureCollection.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 usingAbstractFeatureCollection.iterator()
will perform the same check.- Specified by:
openIterator
in classAbstractFeatureCollection
- Returns:
- Iterator over collection contents
-
add
public boolean add(SimpleFeature f)
- Specified by:
add
in interfaceCollection<SimpleFeature>
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<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 interfaceFeatureCollection<SimpleFeatureType,SimpleFeature>
- Specified by:
features
in interfaceSimpleFeatureCollection
- Overrides:
features
in classAbstractFeatureCollection
- Returns:
- A FeatureIterator.
-
getBounds
public ReferencedEnvelope getBounds()
Description copied from class:AbstractFeatureCollection
Subclasses need to override this.- Specified by:
getBounds
in interfaceFeatureCollection<SimpleFeatureType,SimpleFeature>
- Specified by:
getBounds
in classAbstractFeatureCollection
- Returns:
- An Envelope containing the total bounds of this collection.
-
calculateBounds
protected ReferencedEnvelope calculateBounds()
Calculate bounds from features
-
isEmpty
public boolean isEmpty()
Description copied from interface:FeatureCollection
Returns true if this feature collection contains no features.- Specified by:
isEmpty
in interfaceCollection<SimpleFeature>
- Specified by:
isEmpty
in interfaceFeatureCollection<SimpleFeatureType,SimpleFeature>
- Overrides:
isEmpty
in classAbstractFeatureCollection
- 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:
The above recommended use is agreement with the Collections API precident of List.subList( start, end ).collection.subCollection( filter ).clear();
The results of subCollection:
- are to be considered unordered
- may be an ordered FeatureList if requested when sortBy is indicated
- Specified by:
subCollection
in interfaceFeatureCollection<SimpleFeatureType,SimpleFeature>
- Specified by:
subCollection
in interfaceSimpleFeatureCollection
- Overrides:
subCollection
in classAbstractFeatureCollection
- 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 interfaceFeatureCollection<SimpleFeatureType,SimpleFeature>
- Specified by:
sort
in interfaceSimpleFeatureCollection
- Overrides:
sort
in classAbstractFeatureCollection
- Parameters:
order
- Sort order- Returns:
- FeatureCollection sorted in the indicated order
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection<SimpleFeature>
-
addAll
public boolean addAll(Collection<? extends SimpleFeature> c)
- Specified by:
addAll
in interfaceCollection<SimpleFeature>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAll
in interfaceCollection<SimpleFeature>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAll
in interfaceCollection<SimpleFeature>
-
-