Package io.jenetics
Class CharacterGene
- java.lang.Object
-
- io.jenetics.CharacterGene
-
- All Implemented Interfaces:
Gene<Character,CharacterGene>,Factory<CharacterGene>,Verifiable,Serializable,Comparable<CharacterGene>
public final class CharacterGene extends Object implements Gene<Character,CharacterGene>, Comparable<CharacterGene>, Serializable
Character gene implementation.This is a value-based class; use of identity-sensitive operations (including reference equality (
==), identity hash code, or synchronization) on instances ofCharacterGenemay have unpredictable results and should be avoided.- Since:
- 1.0
- Version:
- 6.0
- See Also:
CharacterChromosome, Serialized Form- Implementation Note:
- This class is immutable and thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description static CharSeqDEFAULT_CHARACTERSThe default character set used by this gene.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Characterallele()Return the allele of this gene.charcharValue()Return thecharvalue of this character gene.intcompareTo(CharacterGene that)booleanequals(Object obj)inthashCode()booleanisValid()Check if this object is valid.booleanisValidCharacter(Character allele)Test, if the given character is valid.CharacterGenenewInstance()Return a new, random gene with the same type and with the same constraints than this gene.CharacterGenenewInstance(Character allele)Create a new character gene from the given character.static CharacterGeneof()Create a new random character gene, chosen from theDEFAULT_CHARACTERS.static CharacterGeneof(char allele)Create a new character gene from the given character.static CharacterGeneof(char allele, CharSeq validCharacters)Create a new CharacterGene from the give character.static CharacterGeneof(CharSeq validCharacters)Create a new CharacterGene with a randomly chosen character from the set of valid characters.StringtoString()CharSeqvalidChars()Return a (unmodifiable) set of valid characters.
-
-
-
Field Detail
-
DEFAULT_CHARACTERS
public static final CharSeq DEFAULT_CHARACTERS
The default character set used by this gene.
-
-
Method Detail
-
isValid
public 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.
-
allele
public Character allele()
Description copied from interface:GeneReturn the allele of this gene.- Specified by:
allelein interfaceGene<Character,CharacterGene>- Returns:
- the allele of this gene.
-
charValue
public char charValue()
Return thecharvalue of this character gene.- Returns:
- the
charvalue.
-
isValidCharacter
public boolean isValidCharacter(Character allele)
Test, if the given character is valid.- Parameters:
allele- The character to test.- Returns:
- true if the character is valid, false otherwise.
-
validChars
public CharSeq validChars()
Return a (unmodifiable) set of valid characters.- Returns:
- the
CharSeqof valid characters.
-
compareTo
public int compareTo(CharacterGene that)
- Specified by:
compareToin interfaceComparable<CharacterGene>- Parameters:
that- The other gene to compare.- Returns:
- the value 0 if the argument Character is equal to this Character; a value less than 0 if this Character is numerically less than the Character argument; and a value greater than 0 if this Character is numerically greater than the Character argument (unsigned comparison). Note that this is strictly a numerical comparison; it is not local-dependent.
- See Also:
Character.compareTo(java.lang.Character)
-
newInstance
public CharacterGene newInstance()
Description copied from interface:GeneReturn a new, random gene with the same type and with the same constraints than this gene. For all genes returned by this method holdsgene.getClass() == gene.newInstance().getClass(). Implementations of this method has to use theRandomobject which can be fetched from theRandomRegistry.- Specified by:
newInstancein interfaceFactory<CharacterGene>- Specified by:
newInstancein interfaceGene<Character,CharacterGene>- Returns:
- a new instance of type T
-
newInstance
public CharacterGene newInstance(Character allele)
Create a new character gene from the given character. If the character is not within thevalidChars(), an invalid gene will be created.- Specified by:
newInstancein interfaceGene<Character,CharacterGene>- Parameters:
allele- the character value of the created gene.- Returns:
- a new character gene.
- Throws:
NullPointerException- if the givencharacterisnull.
-
of
public static CharacterGene of(CharSeq validCharacters)
Create a new CharacterGene with a randomly chosen character from the set of valid characters.- Parameters:
validCharacters- the valid characters for this gene.- Returns:
- a new valid, random gene,
- Throws:
NullPointerException- if thevalidCharactersarenull.
-
of
public static CharacterGene of(char allele)
Create a new character gene from the given character. If the character is not within theDEFAULT_CHARACTERS, an invalid gene will be created.- Parameters:
allele- the character value of the created gene.- Returns:
- a new character gene.
-
of
public static CharacterGene of()
Create a new random character gene, chosen from theDEFAULT_CHARACTERS.- Returns:
- a new random character gene.
-
of
public static CharacterGene of(char allele, CharSeq validCharacters)
Create a new CharacterGene from the give character.- Parameters:
allele- The allele.validCharacters- the valid characters fo the new gene- Returns:
- a new
CharacterGenewith the given parameter - Throws:
NullPointerException- if one of the arguments isnull.IllegalArgumentException- if thevalidCharactersare empty.
-
-