Class MemoryFeatureSet

All Implemented Interfaces:
Data­Set, Feature­Set, Resource

public class MemoryFeatureSet extends AbstractFeatureSet
Set of feature instances stored in memory. Features are specified at construction time. Metadata can be specified by overriding the Abstract­Feature­Set​.create­Metadata() 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 the refresh() 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 by Abstract­Resource​.get­Synchronization­Lock().
Since:
1.6
  • Field Details

  • Constructor Details

    • MemoryFeatureSet

      public MemoryFeatureSet(Collection<AbstractFeature> features)
      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:
      Illegal­Argument­Exception - 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, or null if none.
      base­Type - the base type of all features in the given collection, or null for automatic.
      features - collection of stored features. This collection will not be copied.
      Throws:
      Illegal­Argument­Exception - if base­Type is null and cannot be determined from the feature instances, or if some feature instances are not assignable to base­Type.
  • Method Details

    • refresh

      public void refresh()
      Notifies this Feature­Set that the elements in the collection of features have changed. This method re-verifies that all feature instances are assignable to the base­Type and rebuilds the set of all feature types.
      Throws:
      Illegal­State­Exception - if some features are not instances of base­Type.
    • getType

      public DefaultFeatureType 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

      public OptionalLong getFeatureCount()
      Returns the number of features in this set.
      Overrides:
      get­Feature­Count in class Abstract­Feature­Set
      Returns:
      the number of features.
    • features

      public Stream<AbstractFeature> features(boolean parallel)
      Returns a stream of all features contained in this dataset.
      Parameters:
      parallel - true for a parallel stream (if supported), or false for 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:
      prepare­Query­Optimization in class Abstract­Feature­Set
      Parameters:
      query - definition of feature and feature properties filtering applied at reading time.
      optimizer - the optimization to configure.
      Throws:
      Data­Store­Exception - if an error occurred during the configuration of the optimizer.
      Since:
      1.6
    • equals

      public boolean equals(Object obj)
      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.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare.
      Returns:
      whether the two objects are memory resources wrapping the same features.
    • hashCode

      public int hashCode()
      Returns a hash code value for consistency with equals(Object).
      Overrides:
      hash­Code in class Object
      Returns:
      a hash code value.