public interface Chromosome<G extends Gene<?,G>> extends BaseSeq<G>, Factory<Chromosome<G>>, Verifiable
Genotype
,
Gene
Chromosome
interface must be immutable
and guarantee an efficient random access (O(1)
) to the genes. A
Chromosome
must contains at least one Gene
.Modifier and Type | Method and Description |
---|---|
default <C extends Chromosome<G>> |
as(Class<C> type)
Casts this
Chromosome to an instance of type C . |
default G |
gene()
Return the first gene of this chromosome.
|
default G |
get(int index)
Return the value at the given
index . |
default G |
getGene()
Deprecated.
Use
gene() instead |
G |
getGene(int index)
Deprecated.
Use
get(int) instead. Will be removed. |
Chromosome<G> |
newInstance(ISeq<G> genes)
A factory method which creates a new
Chromosome of specific type
and the given genes . |
ISeq<G> |
toSeq()
|
iterator, length, listIterator, spliterator, stream
instances, newInstance
isValid
default G get(int index)
BaseSeq
index
.default G gene()
@Deprecated G getGene(int index)
get(int)
instead. Will be removed.index
- The gene index.IndexOutOfBoundsException
- if the index is out of range
(index < 1 || index >= length()).@Deprecated default G getGene()
gene()
insteadChromosome<G> newInstance(ISeq<G> genes)
Chromosome
of specific type
and the given genes
.genes
- the genes of the new chromosome. The given genes array is
not copied.Chromosome
of the same type with the given genes.NullPointerException
- if the given gene
s are null
.IllegalArgumentException
- if the length of the given gene sequence
is smaller than one.@Deprecated ISeq<G> toSeq()
BaseSeq
, it
is no longer necessary to get a sequence with genes. If it is
necessary to create an ISeq
from a chromosome, use
ISeq.of(chromosome)
instead. This method will be
removed in the next major release.default <C extends Chromosome<G>> C as(Class<C> type)
Chromosome
to an instance of type C
.
This is a convenient method for an ordinary cast and allows seamless
method-chaining. Instead of
final Genotype<BitGene> gt = ...
final int count = ((BitChromosome)gt.chromosome()).bitCount()
final Genotype<BitGene> gt = ...
final int count = gt.chromosome()
.as(BitChromosome.class)
.bitCount()
C
- the target chromosome typetype
- the target type classC
NullPointerException
- if the target type class is null
ClassCastException
- if this chromosome can't be casted to a
chromosome of type C
© 2007-2020 Franz Wilhelmstötter (2020-02-18 20:01)