Class Extensions
java.lang.Object
org.moeaframework.algorithm.extension.Extensions
- All Implemented Interfaces:
Iterable<Extension>,Configurable,Stateful
A collection of
Extension associated with an Algorithm. Extensions implementing Stateful
and/or Configurable will be handled appropriately.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the extension and invokes itsExtension.onRegister(Algorithm)method.voidapplyConfiguration(TypedProperties properties) Applies the properties to this instance.<T extends Extension>
TGets the extension of the given type.Gets the current configuration of this instance.iterator()voidloadState(ObjectInputStream stream) Loads the state of this object from the stream.voidInvokes theExtension.onInitialize(Algorithm)method for all registered extensions.voidonRun(TerminationCondition terminationCondition) Invokes theExtension.onRun(Algorithm, TerminationCondition)method for all registered extensions.voidonStep()Invokes theExtension.onStep(Algorithm)method for all registered extensions.voidInvokes theExtension.onTerminate(Algorithm)method for all registered extensions.voidRemoves all extensions of the given type (including any that inherit from the type).voidRemoves the extension.voidRemoves all extensions matching the given filter.voidsaveState(ObjectOutputStream stream) Writes the state of this object to the stream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Extensions
Constructs a new collection ofExtension- Parameters:
algorithm- the algorithm associated with the extensions
-
-
Method Details
-
add
Adds the extension and invokes itsExtension.onRegister(Algorithm)method.- Parameters:
extension- the extension to add
-
remove
Removes the extension.- Parameters:
extension- the extension to remove
-
remove
Removes all extensions of the given type (including any that inherit from the type).- Parameters:
extensionType- the extension type to remove
-
removeIf
Removes all extensions matching the given filter.- Parameters:
filter- the filter, returningtrueto remove the extension
-
get
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
nullif no matches found
-
onRun
Invokes theExtension.onRun(Algorithm, TerminationCondition)method for all registered extensions.- Parameters:
terminationCondition- the termination conditions for the run
-
onStep
public void onStep()Invokes theExtension.onStep(Algorithm)method for all registered extensions. -
onInitialize
public void onInitialize()Invokes theExtension.onInitialize(Algorithm)method for all registered extensions. -
onTerminate
public void onTerminate()Invokes theExtension.onTerminate(Algorithm)method for all registered extensions. -
iterator
-
saveState
Description copied from interface:StatefulWrites the state of this object to the stream. The order that objects are written to the stream is important. We recommend first callingsuper.saveState(stream)followed by writing each field.- Specified by:
saveStatein interfaceStateful- Parameters:
stream- the stream- Throws:
IOException- if an I/O error occurred
-
loadState
Description copied from interface:StatefulLoads 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 inStateful.saveState(ObjectOutputStream).- Specified by:
loadStatein interfaceStateful- Parameters:
stream- the stream- Throws:
IOException- if an I/O error occurredClassNotFoundException- if the stream referenced a class that is not defined
-
applyConfiguration
Description copied from interface:ConfigurableApplies 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
Configurableobjects inside this object, they should be updated before callingsuper.applyConfiguration(properties).- Specified by:
applyConfigurationin interfaceConfigurable- Parameters:
properties- the user-defined properties
-
getConfiguration
Description copied from interface:ConfigurableGets 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:
getConfigurationin interfaceConfigurable- Returns:
- the properties defining this instance
-