public interface Chromosome<G extends Gene<?,G>> extends Verifiable, Iterable<G>, Factory<Chromosome<G>>
API Note:
Implementations of the 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 |
getGene()
Return the first gene of this chromosome.
|
G |
getGene(int index)
Return the gene on the specified index.
|
int |
length()
Returns the length of the Chromosome.
|
Chromosome<G> |
newInstance(ISeq<G> genes)
A factory method which creates a new
Chromosome of specific type
and the given genes . |
default Stream<G> |
stream()
Returns a sequential
Stream of genes with this chromosome as
its source. |
ISeq<G> |
toSeq()
Return an unmodifiable sequence of the genes of this chromosome.
|
isValid
forEach, iterator, spliterator
instances, newInstance
Chromosome<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.default G getGene()
G getGene(int index)
index
- The gene index.IndexOutOfBoundsException
- if the index is out of range
(index < 1 || index >= length()).int length()
ISeq<G> toSeq()
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.getChromosome()).bitCount()
final Genotype<BitGene> gt = ...
final int count = gt.getChromosome()
.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-2017 Franz Wilhelmstötter (2017-04-28 16:50)