Package org.opt4j.core
Class AbstractIndividualFactory<I extends Individual>
- java.lang.Object
-
- org.opt4j.core.AbstractIndividualFactory<I>
-
- Type Parameters:
I
- the type of Individual
- All Implemented Interfaces:
IndividualFactory
- Direct Known Subclasses:
DefaultIndividualFactory
,ParticleFactory
public class AbstractIndividualFactory<I extends Individual> extends Object implements IndividualFactory
TheAbstractIndividualFactory
createsIndividual
s using a givenProvider
and sets the registeredIndividualStateListener
s. TheCreator
is used to create the problem specificGenotype
with which the createdIndividual
is initialized.
-
-
Field Summary
Fields Modifier and Type Field Description protected Creator<Genotype>
creator
protected com.google.inject.Provider<I>
individualProvider
protected Set<IndividualStateListener>
individualStateListeners
-
Constructor Summary
Constructors Constructor Description AbstractIndividualFactory(com.google.inject.Provider<I> individualProvider, Creator creator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addIndividualStateListener(IndividualStateListener listener)
Adds anIndividualStateListener
to eachIndividual
that is created by this class.Individual
create()
Creates a newIndividual
.Individual
create(Genotype genotype)
Creates a newIndividual
with a specifiedGenotype
.protected void
injectListeners(Set<IndividualStateListener> listeners)
TheIndividualStateListener
s will be transmitted to eachIndividual
that is created by this class.void
removeIndividualStateListener(IndividualStateListener listener)
Removes anIndividualStateListener
that is invoked if the state of anyIndividual
changes.
-
-
-
Field Detail
-
individualProvider
protected final com.google.inject.Provider<I extends Individual> individualProvider
-
individualStateListeners
protected final Set<IndividualStateListener> individualStateListeners
-
-
Method Detail
-
injectListeners
@Inject protected void injectListeners(Set<IndividualStateListener> listeners)
TheIndividualStateListener
s will be transmitted to eachIndividual
that is created by this class. The listeners are invoked if the state of theIndividual
changes.- Parameters:
listeners
- the listeners
-
addIndividualStateListener
public void addIndividualStateListener(IndividualStateListener listener)
Description copied from interface:IndividualFactory
Adds anIndividualStateListener
to eachIndividual
that is created by this class. This listener is invoked if the state of theIndividual
changes.- Specified by:
addIndividualStateListener
in interfaceIndividualFactory
- Parameters:
listener
- the listener that is invoked if the state of any individual changes- See Also:
IndividualFactory.removeIndividualStateListener(org.opt4j.core.IndividualStateListener)
-
create
public Individual create()
Description copied from interface:IndividualFactory
Creates a newIndividual
.- Specified by:
create
in interfaceIndividualFactory
- Returns:
- the built individual
-
create
public Individual create(Genotype genotype)
Description copied from interface:IndividualFactory
Creates a newIndividual
with a specifiedGenotype
.- Specified by:
create
in interfaceIndividualFactory
- Parameters:
genotype
- the genotype of the individual- Returns:
- the built individual
-
removeIndividualStateListener
public void removeIndividualStateListener(IndividualStateListener listener)
Description copied from interface:IndividualFactory
Removes anIndividualStateListener
that is invoked if the state of anyIndividual
changes. AllIndividual
s created after this method call by thisIndividualFactory
do no longer use the listener.- Specified by:
removeIndividualStateListener
in interfaceIndividualFactory
- Parameters:
listener
- the listener that is invoked if the state of any individual changes- See Also:
IndividualFactory.addIndividualStateListener(org.opt4j.core.IndividualStateListener)
-
-