- All Implemented Interfaces:
Chromosome<CharacterGene>,BaseSeq<CharacterGene>,Factory<Chromosome<CharacterGene>>,Verifiable,Serializable,CharSequence,Iterable<CharacterGene>,RandomAccess
public class CharacterChromosome
extends AbstractChromosome<CharacterGene>
implements CharSequence, Serializable
Character chromosome which represents character sequences.
- Since:
- 1.0
- Version:
- 6.1
- See Also:
- Implementation Note:
- This class is immutable and thread-safe.
-
Field Summary
Fields inherited from class io.jenetics.AbstractChromosome
_genes, _valid -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCharacterChromosome(ISeq<CharacterGene> genes, IntRange lengthRange) Create a new chromosome from the givengenesarray. -
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int index) booleaninthashCode()booleanisEmpty()Returnstrueif this sequence contains no elements.Return the allowed length range of the chromosome.Maps the gene alleles of this chromosome, given aschar[]array, by applying the given mapper functionf.Create a new, random chromosome.newInstance(ISeq<CharacterGene> genes) A factory method which creates a newChromosomeof specific type and the givengenes.static CharacterChromosomeof(int length) Create a new chromosome with theCharacterGene.DEFAULT_CHARACTERSchar set as valid characters.static CharacterChromosomeCreate a new chromosome with thevalidCharacterschar set as valid characters.static CharacterChromosomeCreate a new chromosome with thevalidCharacterschar set as valid characters.static CharacterChromosomeCreate a new chromosome with theCharacterGene.DEFAULT_CHARACTERSchar set as valid characters.static CharacterChromosomeCreate a new chromosome from the given genes (given as string).static CharacterChromosomeCreate a new chromosome from the given genes (given as string).subSequence(int start, int end) char[]toArray()Returns a char array containing all the elements in this chromosome in a proper sequence.char[]toArray(char[] array) Returns a char array containing all the elements in this chromosome in a proper sequence.toString()Methods inherited from class io.jenetics.AbstractChromosome
get, isValid, lengthMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.jenetics.util.BaseSeq
forEach, iterator, listIterator, nonEmpty, spliterator, streamMethods inherited from interface java.lang.CharSequence
chars, codePoints, lengthMethods inherited from interface io.jenetics.Chromosome
as, gene
-
Constructor Details
-
CharacterChromosome
Create a new chromosome from the givengenesarray. The genes array is copied, so changes to the given genes array don't affect the genes of this chromosome.- Parameters:
genes- the genes that form the chromosome.lengthRange- the allowed length range of the chromosome.- Throws:
NullPointerException- if the given gene array isnull.IllegalArgumentException- if the length of the gene array is smaller than one.- Since:
- 4.0
-
-
Method Details
-
charAt
- Specified by:
charAtin interfaceCharSequence
-
isEmpty
Description copied from interface:BaseSeqReturnstrueif this sequence contains no elements.- Specified by:
isEmptyin interfaceBaseSeq<CharacterGene>- Specified by:
isEmptyin interfaceCharSequence- Returns:
trueif this sequence contains no elements
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
newInstance
Description copied from interface:ChromosomeA factory method which creates a newChromosomeof specific type and the givengenes.- Specified by:
newInstancein interfaceChromosome<CharacterGene>- 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 given gene array isnull.
-
newInstance
Create a new, random chromosome.- Specified by:
newInstancein interfaceFactory<Chromosome<CharacterGene>>- Returns:
- a new instance of type T
-
map
Maps the gene alleles of this chromosome, given aschar[]array, by applying the given mapper functionf. The mapped gene values are then wrapped into a newly created chromosome.final CharacterChromosome chromosome = ...; final CharacterChromosome uppercase = chromosome.map(Main::uppercase); static int[] uppercase(final int[] values) { for (int i = 0; i < values.length; ++i) { values[i] = Character.toUpperCase(values[i]); } return values; }- Parameters:
f- the mapper function- Returns:
- a newly created chromosome with the mapped gene values
- Throws:
NullPointerException- if the mapper function isnull.IllegalArgumentException- if the length of the mappedchar[]array is empty or doesn't match with the allowed length range- Since:
- 6.1
-
hashCode
-
equals
-
toString
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classAbstractChromosome<CharacterGene>
-
toArray
Returns a char array containing all the elements in this chromosome in a proper sequence. If the chromosome fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the length of this chromosome.- Parameters:
array- the array into which the elements of this chromosome are to be stored, if it is big enough; otherwise, a new array is allocated for this purpose.- Returns:
- an array containing the elements of this chromosome
- Throws:
NullPointerException- if the givenarrayisnull- Since:
- 3.0
-
toArray
Returns a char array containing all the elements in this chromosome in a proper sequence.- Returns:
- an array containing the elements of this chromosome
- Since:
- 3.0
-
of
Create a new chromosome with thevalidCharacterschar set as valid characters.- Parameters:
validCharacters- the valid characters for this chromosome.lengthRange- the allowed length range of the chromosome.- Returns:
- a new
CharacterChromosomewith the given parameter - Throws:
NullPointerException- if thevalidCharactersisnull.IllegalArgumentException- if the length of the gene sequence is empty, doesn't match with the allowed length range, the minimum or maximum of the range is smaller or equal zero, or the given range size is zero.- Since:
- 4.3
-
of
Create a new chromosome with theCharacterGene.DEFAULT_CHARACTERSchar set as valid characters.- Parameters:
lengthRange- the allowed length range of the chromosome.- Returns:
- a new
CharacterChromosomewith the given parameter - Throws:
IllegalArgumentException- if thelengthis smaller than one.
-
of
Create a new chromosome with thevalidCharacterschar set as valid characters.- Parameters:
validCharacters- the valid characters for this chromosome.length- thelengthof the new chromosome.- Returns:
- a new
CharacterChromosomewith the given parameter - Throws:
NullPointerException- if thevalidCharactersisnull.IllegalArgumentException- if the length of the gene sequence is empty, doesn't match with the allowed length range, the minimum or maximum of the range is smaller or equal zero, or the given range size is zero.- Since:
- 4.3
-
of
Create a new chromosome with theCharacterGene.DEFAULT_CHARACTERSchar set as valid characters.- Parameters:
length- thelengthof the new chromosome.- Returns:
- a new
CharacterChromosomewith the given parameter - Throws:
IllegalArgumentException- if thelengthis smaller than one.
-
of
Create a new chromosome from the given genes (given as string).- Parameters:
alleles- the character genes.validChars- the valid characters.- Returns:
- a new
CharacterChromosomewith the given parameter - Throws:
IllegalArgumentException- if the genes string is empty.
-
of
Create a new chromosome from the given genes (given as string).- Parameters:
alleles- the character genes.- Returns:
- a new
CharacterChromosomewith the given parameter - Throws:
IllegalArgumentException- if the genes string is empty.
-
lengthRange
Return the allowed length range of the chromosome. The minimum value of the range is included and the maximum value is excluded.- Returns:
- the allowed length range of the chromosome
-