java.lang.Object
io.jenetics.IntegerGene
- All Implemented Interfaces:
BoundedGene<Integer,,IntegerGene> Gene<Integer,,IntegerGene> NumericGene<Integer,,IntegerGene> Factory<IntegerGene>,Mean<IntegerGene>,Self<IntegerGene>,Verifiable,Serializable,Comparable<IntegerGene>
public final class IntegerGene
extends Object
implements NumericGene<Integer,IntegerGene>, Mean<IntegerGene>, Comparable<IntegerGene>, Serializable
NumericGene implementation which holds a 32-bit integer number.
This is a
value-based class; use of identity-sensitive operations (including
reference equality (==), identity hash code, or synchronization) on
instances of IntegerGene may have unpredictable results and should
be avoided.
- Since:
- 2.0
- Version:
- 7.0
- See Also:
- Implementation Note:
- This class is immutable and thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionallele()Return the allele of this gene.byteReturns the value of the specified gene as a byte.intcompareTo(IntegerGene other) doubleReturns the value of the specified gene as a double.booleanfloatReturns the value of the specified gene as a float.inthashCode()intintValue()Returns the value of the specified gene as an int.booleanisValid()Check if this object is valid.longReturns the value of the specified gene as a long.max()Return the allowed max value.mean(IntegerGene that) Return the (usually arithmetic) mean value ofthisandthat.min()Return the allowed min value.Return a new, random gene with the same type and with the same constraints as this gene.newInstance(int allele) Create a new gene from the givenvalueand the gene context.newInstance(Integer allele) Create a new gene from the givenvalueand the current bounds.newInstance(Number allele) Create a new gene from the givenvalueand the current bounds.static IntegerGeneof(int min, int max) Create a new randomIntegerGene.static IntegerGeneof(int allele, int min, int max) Create a new randomIntegerGenewith the given value and the given range.static IntegerGeneCreate a new randomIntegerGenewith the given value and the given range.static IntegerGeneCreate a new randomIntegerGene.range()Return the range ofthisgene.shortReturns the value of the specified gene as a short.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.jenetics.BoundedGene
max, min
-
Method Details
-
allele
Description copied from interface:GeneReturn the allele of this gene.- Specified by:
allelein interfaceGene<Integer,IntegerGene> - Returns:
- the allele of this gene.
-
min
Description copied from interface:BoundedGeneReturn the allowed min value.- Specified by:
minin interfaceBoundedGene<Integer,IntegerGene> - Returns:
- The allowed min value.
-
max
Description copied from interface:BoundedGeneReturn the allowed max value.- Specified by:
maxin interfaceBoundedGene<Integer,IntegerGene> - Returns:
- The allowed max value.
-
range
Return the range ofthisgene.- Returns:
- the range of
thisgene - Since:
- 4.4
-
byteValue
Description copied from interface:NumericGeneReturns the value of the specified gene as a byte. This may involve rounding or truncation.- Specified by:
byteValuein interfaceNumericGene<Integer,IntegerGene> - Returns:
- the numeric value represented by this object after conversion to
type
byte.
-
shortValue
Description copied from interface:NumericGeneReturns the value of the specified gene as a short. This may involve rounding or truncation.- Specified by:
shortValuein interfaceNumericGene<Integer,IntegerGene> - Returns:
- the numeric value represented by this object after conversion to
type
short.
-
intValue
Description copied from interface:NumericGeneReturns the value of the specified gene as an int. This may involve rounding or truncation.- Specified by:
intValuein interfaceNumericGene<Integer,IntegerGene> - Returns:
- the numeric value represented by this object after conversion to
type
int.
-
longValue
Description copied from interface:NumericGeneReturns the value of the specified gene as a long. This may involve rounding or truncation.- Specified by:
longValuein interfaceNumericGene<Integer,IntegerGene> - Returns:
- the numeric value represented by this object after conversion to
type
long.
-
floatValue
Description copied from interface:NumericGeneReturns the value of the specified gene as a float. This may involve rounding or truncation.- Specified by:
floatValuein interfaceNumericGene<Integer,IntegerGene> - Returns:
- the numeric value represented by this object after conversion to
type
float.
-
doubleValue
Description copied from interface:NumericGeneReturns the value of the specified gene as a double. This may involve rounding or truncation.- Specified by:
doubleValuein interfaceNumericGene<Integer,IntegerGene> - Returns:
- the numeric value represented by this object after conversion to
type
double.
-
isValid
Description copied from interface:VerifiableCheck if this object is valid.- Specified by:
isValidin interfaceBoundedGene<Integer,IntegerGene> - Specified by:
isValidin interfaceVerifiable- Returns:
- true if this object is valid, false otherwise.
-
compareTo
- Specified by:
compareToin interfaceBoundedGene<Integer,IntegerGene> - Specified by:
compareToin interfaceComparable<IntegerGene>
-
mean
Description copied from interface:MeanReturn the (usually arithmetic) mean value ofthisandthat. ForNumericGenes the mean is the arithmetic mean.- Specified by:
meanin interfaceMean<IntegerGene>- Parameters:
that- the second value for calculating the mean.- Returns:
- the mean value of
thisandthat.
-
newInstance
Create a new gene from the givenvalueand the gene context.- Parameters:
allele- the value of the new gene.- Returns:
- a new gene with the given value.
- Since:
- 5.0
-
newInstance
Description copied from interface:BoundedGeneCreate a new gene from the givenvalueand the current bounds.- Specified by:
newInstancein interfaceBoundedGene<Integer,IntegerGene> - Specified by:
newInstancein interfaceGene<Integer,IntegerGene> - Parameters:
allele- the value of the new gene.- Returns:
- a new gene with the given value.
-
newInstance
Description copied from interface:BoundedGeneCreate a new gene from the givenvalueand the current bounds.- Specified by:
newInstancein interfaceNumericGene<Integer,IntegerGene> - Parameters:
allele- the value of the new gene.- Returns:
- a new gene with the given value.
-
newInstance
Description copied from interface:GeneReturn 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 theRandomGeneratorobject which can be fetched from theRandomRegistry.- Specified by:
newInstancein interfaceFactory<IntegerGene>- Specified by:
newInstancein interfaceGene<Integer,IntegerGene> - Returns:
- a new instance of type T
-
hashCode
-
equals
-
toString
-
of
Create a new randomIntegerGenewith the given value and the given range. If thevalueisn't within the interval[min, max), no exception is thrown. In this case the methodisValid()returnsfalse.- Parameters:
allele- the value of the gene.min- the minimal valid value of this gene (inclusively).max- the maximal valid value of this gene (exclusively).- Returns:
- a new
IntegerGenewith the givenvalue
-
of
Create a new randomIntegerGenewith the given value and the given range. If thevalueisn't within the interval [min, max], no exception is thrown. In this case the methodisValid()returnsfalse.- Parameters:
allele- the value of the gene.range- the integer range to use- Returns:
- a new
IntegerGenewith the givevalue - Throws:
NullPointerException- if the givenrangeisnull.- Since:
- 3.2
-
of
Create a new randomIntegerGene. It is guaranteed that the value of theIntegerGenelies in the interval[min, max).- Parameters:
min- the minimal valid value of this gene (inclusively).max- the maximal valid value of this gene (exclusively).- Returns:
- a new random
IntegerGene - Throws:
IllegalArgumentException- ifmaxis greater than or equal tomin
-
of
Create a new randomIntegerGene. It is guaranteed that the value of theIntegerGenelies in the interval[min, max).- Parameters:
range- the integer range to use- Returns:
- a new random
IntegerGene - Throws:
NullPointerException- if the givenrangeisnull.IllegalArgumentException- ifmaxis greater than or equal tomin- Since:
- 3.2
-