Class Extensions

java.lang.Object
org.moeaframework.algorithm.extension.Extensions
All Implemented Interfaces:
Iterable<Extension>, Configurable, Stateful

public class Extensions extends Object implements Iterable<Extension>, Stateful, Configurable
A collection of Extension associated with an Algorithm. Extensions implementing Stateful and/or Configurable will be handled appropriately.
  • Constructor Details

    • Extensions

      public Extensions(Algorithm algorithm)
      Constructs a new collection of Extension
      Parameters:
      algorithm - the algorithm associated with the extensions
  • Method Details

    • add

      public void add(Extension extension)
      Adds the extension and invokes its Extension.onRegister(Algorithm) method.
      Parameters:
      extension - the extension to add
    • remove

      public void remove(Extension extension)
      Removes the extension.
      Parameters:
      extension - the extension to remove
    • remove

      public void remove(Class<? extends Extension> extensionType)
      Removes all extensions of the given type (including any that inherit from the type).
      Parameters:
      extensionType - the extension type to remove
    • removeIf

      public void removeIf(Predicate<? super Extension> filter)
      Removes all extensions matching the given filter.
      Parameters:
      filter - the filter, returning true to remove the extension
    • get

      public <T extends Extension> T get(Class<T> extensionType)
      Gets the extension of the given type. If there are multiple matching extensions, only the first is returned.
      Type Parameters:
      T - the type of extension
      Parameters:
      extensionType - the type of the extension
      Returns:
      the extension, or null if no matches found
    • onStep

      public void onStep()
      Invokes the Extension.onStep(Algorithm) method for all registered extensions.
    • onInitialize

      public void onInitialize()
      Invokes the Extension.onInitialize(Algorithm) method for all registered extensions.
    • onTerminate

      public void onTerminate()
      Invokes the Extension.onTerminate(Algorithm) method for all registered extensions.
    • iterator

      public Iterator<Extension> iterator()
      Specified by:
      iterator in interface Iterable<Extension>
    • saveState

      public void saveState(ObjectOutputStream stream) throws IOException
      Description copied from interface: Stateful
      Writes the state of this object to the stream. The order that objects are written to the stream is important. We recommend first calling super.saveState(stream) followed by writing each field.
      Specified by:
      saveState in interface Stateful
      Parameters:
      stream - the stream
      Throws:
      IOException - if an I/O error occurred
    • loadState

      public void loadState(ObjectInputStream stream) throws IOException, ClassNotFoundException
      Description copied from interface: Stateful
      Loads the state of this object from the stream. The order for reading objects from the stream must match the order they are written to the stream in Stateful.saveState(ObjectOutputStream).
      Specified by:
      loadState in interface Stateful
      Parameters:
      stream - the stream
      Throws:
      IOException - if an I/O error occurred
      ClassNotFoundException - if the stream referenced a class that is not defined
    • applyConfiguration

      public void applyConfiguration(TypedProperties properties)
      Description copied from interface: Configurable
      Applies the properties to this instance. It is strongly recommended to apply a configuration immediately after creating the instance, as some properties can not be changed after the class is used. Exceptions may be thrown if attempting to set such properties. After calling this method, we encourage users to call TypedProperties.warnIfUnaccessedProperties() to verify all properties were processed. This can identify simple mistakes like typos. If overriding this method, properties should only be updated if a new value is provided. Additionally, if updating any Configurable objects inside this object, they should be updated before calling super.applyConfiguration(properties).
      Specified by:
      applyConfiguration in interface Configurable
      Parameters:
      properties - the user-defined properties
    • getConfiguration

      public TypedProperties getConfiguration()
      Description copied from interface: Configurable
      Gets the current configuration of this instance. In theory, these properties should be able to create a duplicate instance. Note however, they are unlikely to behave identically due to random numbers and other transient fields.
      Specified by:
      getConfiguration in interface Configurable
      Returns:
      the properties defining this instance