java.lang.Object
io.jenetics.CharacterGene
- All Implemented Interfaces:
Gene<Character,
,CharacterGene> Factory<CharacterGene>
,Self<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 of CharacterGene
may have unpredictable results and should
be avoided.
- Since:
- 1.0
- Version:
- 6.0
- See Also:
- Implementation Note:
- This class is immutable and thread-safe.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final CharSeq
The default character set used by this gene. -
Method Summary
Modifier and TypeMethodDescriptionallele()
Return the allele of this gene.char
Return thechar
value of this character gene.int
compareTo
(CharacterGene that) boolean
int
hashCode()
boolean
isValid()
Check if this object is valid.boolean
isValidCharacter
(Character allele) Test, if the given character is valid.Return a new, random gene with the same type and with the same constraints as this gene.newInstance
(Character allele) Create a new character gene from the given character.static CharacterGene
of()
Create a new random character gene, chosen from theDEFAULT_CHARACTERS
.static CharacterGene
of
(char allele) Create a new character gene from the given character.static CharacterGene
Create a new CharacterGene from the give character.static CharacterGene
Create a new CharacterGene with a randomly chosen character from the set of valid characters.toString()
Return a (unmodifiable) set of valid characters.
-
Field Details
-
DEFAULT_CHARACTERS
The default character set used by this gene.
-
-
Method Details
-
isValid
Description copied from interface:Verifiable
Check if this object is valid.- Specified by:
isValid
in interfaceVerifiable
- Returns:
- true if this object is valid, false otherwise.
-
allele
Description copied from interface:Gene
Return the allele of this gene.- Specified by:
allele
in interfaceGene<Character,
CharacterGene> - Returns:
- the allele of this gene.
-
charValue
Return thechar
value of this character gene.- Returns:
- the
char
value.
-
isValidCharacter
Test, if the given character is valid.- Parameters:
allele
- The character to test.- Returns:
- true if the character is valid, false otherwise.
-
validChars
Return a (unmodifiable) set of valid characters.- Returns:
- the
CharSeq
of valid characters.
-
compareTo
- Specified by:
compareTo
in interfaceComparable<CharacterGene>
- Parameters:
that
- The other gene to compare.- Returns:
- 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:
-
hashCode
-
equals
-
toString
-
newInstance
Description copied from interface:Gene
Return a new, random gene with the same type and with the same constraints as this gene. For all genes returned by this method holdsgene.getClass() == gene.newInstance().getClass()
. Implementations of this method have to use theRandom
object which can be fetched from theRandomRegistry
.- Specified by:
newInstance
in interfaceFactory<CharacterGene>
- Specified by:
newInstance
in interfaceGene<Character,
CharacterGene> - Returns:
- a new instance of type T
-
newInstance
Create a new character gene from the given character. If the character is not within thevalidChars()
, an invalid gene will be created.- Specified by:
newInstance
in interfaceGene<Character,
CharacterGene> - Parameters:
allele
- the character value of the created gene.- Returns:
- a new character gene.
- Throws:
NullPointerException
- if the givencharacter
isnull
.
-
of
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 thevalidCharacters
arenull
.
-
of
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
Create a new random character gene, chosen from theDEFAULT_CHARACTERS
.- Returns:
- a new random character gene.
-
of
Create a new CharacterGene from the give character.- Parameters:
allele
- The allele.validCharacters
- the valid characters for the new gene- Returns:
- a new
CharacterGene
with the given parameter - Throws:
NullPointerException
- if one of the arguments isnull
.IllegalArgumentException
- if thevalidCharacters
are empty.
-