Class SharedFeatures

Object
SharedFeatures
All Implemented Interfaces:
Iterable<NameValue<Feature<FeatureInput>>>, NamedProvider<Feature<FeatureInput>>

public class SharedFeatures extends Object implements NamedProvider<Feature<FeatureInput>>, Iterable<NameValue<Feature<FeatureInput>>>
A group of features made available to other features to reference.

The features may have heterogeneous feature input-type, and are therefore stored with FeatureInput input-type, as this is the parent type for all feature-inputs.

This is the principle class for storing all available shared-features.

Author:
Owen Feehan
  • Constructor Details

    • SharedFeatures

      public SharedFeatures()
      Create empty, without any features.
  • Method Details

    • subsetCompatibleWith

      public <S extends FeatureInput> SharedFeaturesSubset<S> subsetCompatibleWith(Class<? extends FeatureInput> inputType)
      Extracts the subset of inputs that are compatible with a particular input-type.
      Parameters:
      inputType - the class of input-type which we search for features to be compatible with.
      Returns:
      a new SharedFeaturesSubset containing only the features considered compatible with inputType.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • contains

      public boolean contains(Feature<FeatureInput> feature)
      Whether a particular feature is contained in this instance.

      This is checked in constant average-case lookup time.

      Parameters:
      feature - the feature to check.
      Returns:
      true if the feature is contained, false otherwise.
    • duplicate

      public SharedFeatures duplicate()
      A deep copy of the current instance.
      Returns:
      a deep copy.
    • addFromProviders

      public void addFromProviders(NamedProvider<FeatureList<FeatureInput>> provider)
      Add features from a NamedProvider of feature-lists.

      Each Feature is added directly (without duplication).

      Parameters:
      provider - the provider to add features from.
    • addFromList

      public void addFromList(FeatureList<FeatureInput> list)
      Add features from a feature-list.

      Each Feature is added directly (without duplication).

      Parameters:
      list - the list to add features from.
    • removeIfExists

      public void removeIfExists(FeatureList<FeatureInput> featuresToRemove)
      Remove all features, if they currently exist, from features.
      Parameters:
      featuresToRemove - a list of features to remove.
    • iterator

      public Iterator<NameValue<Feature<FeatureInput>>> iterator()
      Specified by:
      iterator in interface Iterable<NameValue<Feature<FeatureInput>>>
    • getOptional

      public Optional<Feature<FeatureInput>> getOptional(String key)
      Description copied from interface: NamedProvider
      Retrieves the item if it exists, or returns Optional.empty() if it doesn't exist.

      Note that a 'key' might still throw an exception for another reason (but never because a particular key is absent).

      Specified by:
      getOptional in interface NamedProvider<Feature<FeatureInput>>
      Parameters:
      key - a unique name for the item.
      Returns:
      the item, if it exists, otherwise Optional.empty().
    • keys

      public Set<String> keys()
      Description copied from interface: NamedProvider
      Returns a set of keys associated with the provider.

      There's no guarantee that it refers to all valid keys.

      Specified by:
      keys in interface NamedProvider<Feature<FeatureInput>>
      Returns:
      a set of all keys associated with the provider.