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
A specificCompositeGenotype
is a base class forGenotype
classes that consist of multipleGenotype
s. The methodsize()
returns the sum of the sizes of the containedGenotype
s.CompositeGenotype
has to add each containedGenotype
by calling the methodput(Object, Genotype)
whereObject
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); } }
-
-
Constructor Summary
Constructors Constructor Description CompositeGenotype()
Constructs aCompositeGenotype
.CompositeGenotype(Map<K,V> map)
Constructs aCompositeGenotype
with values from a given map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes allkey
,value
pairs.<G> G
get(Object key)
Iterator<Map.Entry<K,V>>
iterator()
Set<K>
keySet()
Returns allkeys
.<G extends Genotype>
GnewInstance()
Constructs a new (empty) instance of thisGenotype
.void
put(K key, V value)
Adds akey
,value
pair.int
size()
The number of atomic elements of theGenotype
.String
toString()
Collection<V>
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
-
-
-
-
Constructor Detail
-
CompositeGenotype
public CompositeGenotype()
Constructs aCompositeGenotype
.
-
CompositeGenotype
public CompositeGenotype(Map<K,V> map)
Constructs aCompositeGenotype
with values from a given map.- Parameters:
map
- initial values
-
-
Method Detail
-
size
public int size()
Description copied from interface:Genotype
The number of atomic elements of theGenotype
.
-
get
public <G> G get(Object key)
- Type Parameters:
G
- the type of genotype- Parameters:
key
- the key- Returns:
- the addressed genotype
-
put
public void put(K key, V value)
Adds akey
,value
pair.- Parameters:
key
- the keyvalue
- the value (Genotype
)
-
clear
public void clear()
Removes allkey
,value
pairs.
-
values
public Collection<V> values()
Returns allvalues
which are the containedGenotype
objects.- Returns:
- all
values
-
newInstance
public <G extends Genotype> G 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
-
-