Package io.jenetics
Interface Chromosome<G extends Gene<?,G>>
-
- All Superinterfaces:
BaseSeq<G>,Factory<Chromosome<G>>,Iterable<G>,RandomAccess,Verifiable
- All Known Subinterfaces:
BoundedChromosome<A,G>,NumericChromosome<N,G>
- All Known Implementing Classes:
AbstractChromosome,AnyChromosome,BitChromosome,CharacterChromosome,DoubleChromosome,IntegerChromosome,LongChromosome,PermutationChromosome
public interface Chromosome<G extends Gene<?,G>> extends BaseSeq<G>, Factory<Chromosome<G>>, Verifiable
A chromosome consists of one or more genes. It also provides a factory method for creating new, random chromosome instances of the same type and the same constraint.- Since:
- 1.0
- Version:
- 6.0
- See Also:
- Wikipedia: Chromosome,
Genotype,Gene - Implementation Requirements:
- Implementations of the
Chromosomeinterface must be immutable and guarantee an efficient random access (O(1)) to the genes. AChromosomemust contains at least oneGene.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <C extends Chromosome<G>>
Cas(Class<C> type)Casts thisChromosometo an instance of typeC.default Ggene()Return the first gene of this chromosome.default booleanisValid()Check if this object is valid.Chromosome<G>newInstance(ISeq<G> genes)A factory method which creates a newChromosomeof specific type and the givengenes.-
Methods inherited from interface io.jenetics.util.BaseSeq
get, isEmpty, iterator, length, listIterator, nonEmpty, spliterator, stream
-
Methods inherited from interface io.jenetics.util.Factory
instances, newInstance
-
-
-
-
Method Detail
-
gene
default G gene()
Return the first gene of this chromosome. Each chromosome must contain at least one gene.- Returns:
- the first gene of this chromosome.
- Since:
- 5.2
-
isValid
default boolean isValid()
Description copied from interface:VerifiableCheck if this object is valid.- Specified by:
isValidin interfaceVerifiable- Returns:
- true if this object is valid, false otherwise.
-
newInstance
Chromosome<G> newInstance(ISeq<G> genes)
A factory method which creates a newChromosomeof specific type and the givengenes.- Parameters:
genes- the genes of the new chromosome. The given genes array is not copied.- Returns:
- A new
Chromosomeof the same type with the given genes. - Throws:
NullPointerException- if the givengenes arenull.IllegalArgumentException- if the length of the given gene sequence is smaller than one.
-
as
default <C extends Chromosome<G>> C as(Class<C> type)
Casts thisChromosometo an instance of typeC. This is a convenient method for an ordinary cast and allows seamless method-chaining. Instead ofyou can writefinal Genotype<BitGene> gt = ... final int count = ((BitChromosome)gt.chromosome()).bitCount()This may lead to a more elegant programming style in some cases.final Genotype<BitGene> gt = ... final int count = gt.chromosome() .as(BitChromosome.class) .bitCount()- Type Parameters:
C- the target chromosome type- Parameters:
type- the target type class- Returns:
- this chromosome casted as
C - Throws:
NullPointerException- if the target type class isnullClassCastException- if this chromosome can't be casted to a chromosome of typeC- Since:
- 3.7
-
-