org.opt4j.core
Class AbstractIndividualFactory<I extends Individual>

java.lang.Object
  extended by org.opt4j.core.AbstractIndividualFactory<I>
Type Parameters:
I - the type of Individual
All Implemented Interfaces:
IndividualFactory
Direct Known Subclasses:
DefaultIndividualFactory

public class AbstractIndividualFactory<I extends Individual>
extends java.lang.Object
implements IndividualFactory

The AbstractIndividualFactory creates Individuals using a given Provider and sets the registered IndividualStateListeners. The Creator is used to create the problem specific Genotype with which the created Individual is initialized.


Field Summary
protected  Creator<Genotype> creator
           
protected  com.google.inject.Provider<I> individualProvider
           
protected  java.util.Set<IndividualStateListener> individualStateListeners
           
 
Constructor Summary
AbstractIndividualFactory(com.google.inject.Provider<I> individualProvider, Creator<Genotype> creator)
          Constructs an AbstractIndividualFactory with a Provider for Individuals.
 
Method Summary
 void addIndividualStateListener(IndividualStateListener listener)
          Adds an IndividualStateListener to each Individual that is created by this class.
 Individual create()
          Creates a new Individual.
 Individual create(Genotype genotype)
          Creates a new Individual with a specified Genotype.
protected  void injectListeners(java.util.Set<IndividualStateListener> listeners)
          The IndividualStateListeners will be transmitted to each Individual that is created by this class.
 void removeIndividualStateListener(IndividualStateListener listener)
          Removes an IndividualStateListener that is invoked if the state of any Individual changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

creator

protected final Creator<Genotype> creator

individualProvider

protected final com.google.inject.Provider<I extends Individual> individualProvider

individualStateListeners

protected final java.util.Set<IndividualStateListener> individualStateListeners
Constructor Detail

AbstractIndividualFactory

public AbstractIndividualFactory(com.google.inject.Provider<I> individualProvider,
                                 Creator<Genotype> creator)
Constructs an AbstractIndividualFactory with a Provider for Individuals.

Parameters:
individualProvider - the provider that creates new individuals
creator - the creator that creates random genotypes
Method Detail

injectListeners

@Inject
protected void injectListeners(java.util.Set<IndividualStateListener> listeners)
The IndividualStateListeners will be transmitted to each Individual that is created by this class. The listeners are invoked if the state of the Individual changes.

Parameters:
listeners - the listeners

addIndividualStateListener

public void addIndividualStateListener(IndividualStateListener listener)
Description copied from interface: IndividualFactory
Adds an IndividualStateListener to each Individual that is created by this class. This listener is invoked if the state of the Individual changes.

Specified by:
addIndividualStateListener in interface IndividualFactory
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 new Individual.

Specified by:
create in interface IndividualFactory
Returns:
the built individual

create

public Individual create(Genotype genotype)
Description copied from interface: IndividualFactory
Creates a new Individual with a specified Genotype.

Specified by:
create in interface IndividualFactory
Parameters:
genotype - the genotype of the individual
Returns:
the built individual

removeIndividualStateListener

public void removeIndividualStateListener(IndividualStateListener listener)
Description copied from interface: IndividualFactory
Removes an IndividualStateListener that is invoked if the state of any Individual changes. All Individuals created after this method call by this IndividualFactory do no longer use the listener.

Specified by:
removeIndividualStateListener in interface IndividualFactory
Parameters:
listener - the listener that is invoked if the state of any individual changes
See Also:
IndividualFactory.addIndividualStateListener(org.opt4j.core.IndividualStateListener)