Package org.opt4j.genotype
Class CompositeGenotype<K,V extends Genotype>
java.lang.Object
org.opt4j.genotype.CompositeGenotype<K,V>
- Type Parameters:
K
- the type of key for the mappingV
- the type ofGenotype
public class CompositeGenotype<K,V extends Genotype>
extends Object
implements Genotype, Iterable<Map.Entry<K,V>>
The CompositeGenotype
is a base class for Genotype
classes
that consist of multiple Genotype
s. The method
size()
returns the sum of the sizes of the
contained Genotype
s.
CompositeGenotype
has to add each contained
Genotype
by calling the method put(Object, Genotype)
where
Object
is an arbitrary identifier.
Example:
SpecificGenotype extends CompositeGenotype<Integer, Genotype> { public void setDoubleVector(DoubleGenotype genotype){ put(0, genotype); } public DoubleGenotype getDoubleVector(){ return get(0); } public void setBinaryVector(BooleanGenotype genotype){ put(1, genotype); } public BooleanGenotype getDoubleVector(){ return get(1); } }
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstructs aCompositeGenotype
.CompositeGenotype
(Map<K, V> map) Constructs aCompositeGenotype
with values from a given map. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes allkey
,value
pairs.<G> G
iterator()
keySet()
Returns allkeys
.<G extends Genotype>
GConstructs a new (empty) instance of thisGenotype
.void
Adds akey
,value
pair.int
size()
The number of atomic elements of theGenotype
.toString()
values()
Returns allvalues
which are the containedGenotype
objects.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
map
-
-
Constructor Details
-
CompositeGenotype
public CompositeGenotype()Constructs aCompositeGenotype
. -
CompositeGenotype
Constructs aCompositeGenotype
with values from a given map.- Parameters:
map
- initial values
-
-
Method Details
-
size
public int size()Description copied from interface:Genotype
The number of atomic elements of theGenotype
. -
get
- Type Parameters:
G
- the type of genotype- Parameters:
key
- the key- Returns:
- the addressed genotype
-
put
Adds akey
,value
pair.- Parameters:
key
- the keyvalue
- the value (Genotype
)
-
clear
public void clear()Removes allkey
,value
pairs. -
keySet
Returns allkeys
.- Returns:
- all
keys
-
values
Returns allvalues
which are the containedGenotype
objects.- Returns:
- all
values
-
iterator
-
newInstance
Description copied from interface:Genotype
Constructs a new (empty) instance of thisGenotype
.- Specified by:
newInstance
in interfaceGenotype
- Type Parameters:
G
- the type of genotype for an implicit cast- Returns:
- new instance of the genotype
-
toString
-