Class MemoryFeatureSet
Object
AbstractResource
AbstractFeatureSet
MemoryFeatureSet
- All Implemented Interfaces:
DataSet, FeatureSet, Resource
Set of feature instances stored in memory.
Features are specified at construction time.
Metadata can be specified by overriding the
AbstractFeatureSet.createMetadata() method.
When to use
This class is useful for small sets of features, or for testing purposes, or when the features are in memory anyway (for example, a computation result). It should generally not be used for large data sets read from files or databases.Mutability
By default, the feature collection given at construction time is assumed stable. If the content of that collection is modified, then therefresh() method
should be invoked for rebuilding the set of feature types.
Thread-safety
This class is thread-safe if the collection given at construction time is thread-safe. Synchronizations use the lock returned byAbstractResource.getSynchronizationLock().- Since:
- 1.6
-
Nested Class Summary
Nested classes/interfaces inherited from interface Resource
Resource.FileSet -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Set<DefaultFeatureType> The types, including sub-types, of all feature instances found in the collection.protected final DefaultFeatureTypeThe base type of all feature instances that the collection can contain.protected final Collection<AbstractFeature> The features specified at construction time, potentially as a modifiable collection.Fields inherited from class AbstractResource
listeners -
Constructor Summary
ConstructorsConstructorDescriptionMemoryFeatureSet(Collection<AbstractFeature> features) Creates a new set of feature instances stored in memory.MemoryFeatureSet(Resource parent, DefaultFeatureType baseType, Collection<AbstractFeature> features) Creates a new set of feature instances stored in memory with specified parent resource and base type. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTests whether this memory feature set is wrapping the same feature instances as the given object.features(boolean parallel) Returns a stream of all features contained in this dataset.Returns the number of features in this set.getType()Returns the type common to all feature instances in this set.intReturns a hash code value for consistency withequals(Object).protected voidprepareQueryOptimization(FeatureQuery query, Optimization optimizer) Configures the optimization of a query with information about the expected types of all feature instances.voidrefresh()Notifies thisFeatureSetthat the elements in the collection of features have changed.Methods inherited from class AbstractFeatureSet
createMetadata, getIdentifierMethods inherited from class AbstractResource
addListener, clearCache, getEnvelope, getMetadata, getSynchronizationLock, removeListenerMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DataSet
getEnvelopeMethods inherited from interface Resource
addListener, getFileSet, getMetadata, removeListener
-
Field Details
-
baseType
The base type of all feature instances that the collection can contain. All elements ofallTypesmust be assignable to this base type.- See Also:
-
allTypes
The types, including sub-types, of all feature instances found in the collection. This is often a singleton containing onlybaseType, but it may also be a set withoutbaseTypeif all features are instances of various subtypes.This set is modifiable and is updated when
refresh()is invoked. This set should always contains at least one element.- See Also:
-
features
The features specified at construction time, potentially as a modifiable collection. For all feature instances in this collection, the value returned byAbstractFeature.getType()shall bebaseTypeor a subtype ofbaseType.- See Also:
-
-
Constructor Details
-
MemoryFeatureSet
Creates a new set of feature instances stored in memory. The base feature type is determined automatically from the given collection of features. The collection shall contain at least one element.- Parameters:
features- collection of stored features. This collection will not be copied.- Throws:
IllegalArgumentException- if the given collection is empty or does not contain feature instances having a common parent type.
-
MemoryFeatureSet
public MemoryFeatureSet(Resource parent, DefaultFeatureType baseType, Collection<AbstractFeature> features) Creates a new set of feature instances stored in memory with specified parent resource and base type. This constructor verifies that all feature instances are assignable to a base type. That base type can be either specified explicitly or inferred automatically.- Parameters:
parent- the parent resource, ornullif none.baseType- the base type of all features in the given collection, ornullfor automatic.features- collection of stored features. This collection will not be copied.- Throws:
IllegalArgumentException- ifbaseTypeis null and cannot be determined from the feature instances, or if some feature instances are not assignable tobaseType.
-
-
Method Details
-
refresh
public void refresh()Notifies thisFeatureSetthat the elements in the collection of features have changed. This method re-verifies that all feature instances are assignable to thebaseTypeand rebuilds the set of all feature types.- Throws:
IllegalStateException- if some features are not instances ofbaseType.
-
getType
Returns the type common to all feature instances in this set. By default, this type is determined at construction time and does not change even if the content of the feature collection is updated.- Returns:
- a description of properties that are common to all features in this dataset.
-
getFeatureCount
Returns the number of features in this set.- Overrides:
getFeatureCountin classAbstractFeatureSet- Returns:
- the number of features.
-
features
Returns a stream of all features contained in this dataset.- Parameters:
parallel-truefor a parallel stream (if supported), orfalsefor a sequential stream.- Returns:
- all features contained in this dataset.
-
prepareQueryOptimization
protected void prepareQueryOptimization(FeatureQuery query, Optimization optimizer) throws DataStoreException Configures the optimization of a query with information about the expected types of all feature instances. This method is invoked indirectly when a feature subset is created from a query. The optimization depends on the set of all feature types found in the collection.- Overrides:
prepareQueryOptimizationin classAbstractFeatureSet- Parameters:
query- definition of feature and feature properties filtering applied at reading time.optimizer- the optimization to configure.- Throws:
DataStoreException- if an error occurred during the configuration of the optimizer.- Since:
- 1.6
-
equals
Tests whether this memory feature set is wrapping the same feature instances as the given object. This method checks also that the listeners are equal. -
hashCode
-