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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the extension and invokes itsExtension.onRegister(Algorithm)
method.void
applyConfiguration
(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()
void
loadState
(ObjectInputStream stream) Loads the state of this object from the stream.void
Invokes theExtension.onInitialize(Algorithm)
method for all registered extensions.void
onStep()
Invokes theExtension.onStep(Algorithm)
method for all registered extensions.void
Invokes theExtension.onTerminate(Algorithm)
method for all registered extensions.void
Removes all extensions of the given type (including any that inherit from the type).void
Removes the extension.void
Removes all extensions matching the given filter.void
saveState
(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, wait
Methods 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, returningtrue
to 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
null
if no matches found
-
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:Stateful
Writes 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:
saveState
in interfaceStateful
- Parameters:
stream
- the stream- Throws:
IOException
- if an I/O error occurred
-
loadState
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 inStateful.saveState(ObjectOutputStream)
.- Specified by:
loadState
in 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: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 callTypedProperties.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 anyConfigurable
objects inside this object, they should be updated before callingsuper.applyConfiguration(properties)
.- Specified by:
applyConfiguration
in interfaceConfigurable
- Parameters:
properties
- the user-defined properties
-
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 interfaceConfigurable
- Returns:
- the properties defining this instance
-