Package io.jenetics
Class DoubleGene
- java.lang.Object
-
- io.jenetics.DoubleGene
-
- All Implemented Interfaces:
BoundedGene<Double,DoubleGene>
,Gene<Double,DoubleGene>
,NumericGene<Double,DoubleGene>
,Factory<DoubleGene>
,Mean<DoubleGene>
,Verifiable
,Serializable
,Comparable<DoubleGene>
public final class DoubleGene extends Object implements NumericGene<Double,DoubleGene>, Mean<DoubleGene>, Comparable<DoubleGene>, Serializable
Implementation of the NumericGene which holds a 64 bit floating point number.This is a value-based class; use of identity-sensitive operations (including reference equality (
==
), identity hash code, or synchronization) on instances ofDoubleGene
may have unpredictable results and should be avoided.- Since:
- 1.6
- Version:
- 6.0
- See Also:
DoubleChromosome
, Serialized Form- Implementation Note:
- This class is immutable and thread-safe.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Double
allele()
Return the allele of this gene.byte
byteValue()
Returns the value of the specified gene as an byte.int
compareTo(DoubleGene other)
double
doubleValue()
Returns the value of the specified gene as an double.boolean
equals(Object obj)
float
floatValue()
Returns the value of the specified gene as an float.int
hashCode()
int
intValue()
Returns the value of the specified gene as an int.boolean
isValid()
Check if this object is valid.long
longValue()
Returns the value of the specified gene as an long.Double
max()
Return the allowed max value.DoubleGene
mean(DoubleGene that)
Return the (usually arithmetic) mean value ofthis
andthat
.Double
min()
Return the allowed min value.DoubleGene
newInstance()
Return a new, random gene with the same type and with the same constraints than this gene.DoubleGene
newInstance(double allele)
Create a new gene from the givenvalue
and the gene context.DoubleGene
newInstance(Double allele)
Create a new gene from the givenvalue
and the current bounds.DoubleGene
newInstance(Number allele)
Create a new gene from the givenvalue
and the current bounds.static DoubleGene
of(double min, double max)
Create a new randomDoubleGene
.static DoubleGene
of(double allele, double min, double max)
Create a new randomDoubleGene
with the given value and the given range.static DoubleGene
of(double allele, DoubleRange range)
Create a new randomDoubleGene
with the given value and the given range.static DoubleGene
of(DoubleRange range)
Create a new randomDoubleGene
.DoubleRange
range()
Return the range ofthis
gene.short
shortValue()
Returns the value of the specified gene as an short.String
toString()
-
-
-
Method Detail
-
allele
public Double allele()
Description copied from interface:Gene
Return the allele of this gene.- Specified by:
allele
in interfaceGene<Double,DoubleGene>
- Returns:
- the allele of this gene.
-
min
public Double min()
Description copied from interface:BoundedGene
Return the allowed min value.- Specified by:
min
in interfaceBoundedGene<Double,DoubleGene>
- Returns:
- The allowed min value.
-
max
public Double max()
Description copied from interface:BoundedGene
Return the allowed max value.- Specified by:
max
in interfaceBoundedGene<Double,DoubleGene>
- Returns:
- The allowed max value.
-
range
public DoubleRange range()
Return the range ofthis
gene.- Returns:
- the range of
this
gene - Since:
- 4.4
-
byteValue
public byte byteValue()
Description copied from interface:NumericGene
Returns the value of the specified gene as an byte. This may involve rounding or truncation.- Specified by:
byteValue
in interfaceNumericGene<Double,DoubleGene>
- Returns:
- the numeric value represented by this object after conversion to
type
byte
.
-
shortValue
public short shortValue()
Description copied from interface:NumericGene
Returns the value of the specified gene as an short. This may involve rounding or truncation.- Specified by:
shortValue
in interfaceNumericGene<Double,DoubleGene>
- Returns:
- the numeric value represented by this object after conversion to
type
short
.
-
intValue
public int intValue()
Description copied from interface:NumericGene
Returns the value of the specified gene as an int. This may involve rounding or truncation.- Specified by:
intValue
in interfaceNumericGene<Double,DoubleGene>
- Returns:
- the numeric value represented by this object after conversion to
type
int
.
-
longValue
public long longValue()
Description copied from interface:NumericGene
Returns the value of the specified gene as an long. This may involve rounding or truncation.- Specified by:
longValue
in interfaceNumericGene<Double,DoubleGene>
- Returns:
- the numeric value represented by this object after conversion to
type
long
.
-
floatValue
public float floatValue()
Description copied from interface:NumericGene
Returns the value of the specified gene as an float. This may involve rounding or truncation.- Specified by:
floatValue
in interfaceNumericGene<Double,DoubleGene>
- Returns:
- the numeric value represented by this object after conversion to
type
float
.
-
doubleValue
public double doubleValue()
Description copied from interface:NumericGene
Returns the value of the specified gene as an double. This may involve rounding or truncation.- Specified by:
doubleValue
in interfaceNumericGene<Double,DoubleGene>
- Returns:
- the numeric value represented by this object after conversion to
type
double
.
-
isValid
public boolean isValid()
Description copied from interface:Verifiable
Check if this object is valid.- Specified by:
isValid
in interfaceBoundedGene<Double,DoubleGene>
- Specified by:
isValid
in interfaceVerifiable
- Returns:
- true if this object is valid, false otherwise.
-
compareTo
public int compareTo(DoubleGene other)
- Specified by:
compareTo
in interfaceBoundedGene<Double,DoubleGene>
- Specified by:
compareTo
in interfaceComparable<DoubleGene>
-
mean
public DoubleGene mean(DoubleGene that)
Description copied from interface:Mean
Return the (usually arithmetic) mean value ofthis
andthat
. ForNumericGene
s the mean is the arithmetic mean.- Specified by:
mean
in interfaceMean<DoubleGene>
- Parameters:
that
- the second value for calculating the mean.- Returns:
- the mean value of
this
andthat
.
-
newInstance
public DoubleGene newInstance(double allele)
Create a new gene from the givenvalue
and the gene context.- Parameters:
allele
- the value of the new gene.- Returns:
- a new gene with the given value.
- Since:
- 5.0
-
newInstance
public DoubleGene newInstance(Double allele)
Description copied from interface:BoundedGene
Create a new gene from the givenvalue
and the current bounds.- Specified by:
newInstance
in interfaceBoundedGene<Double,DoubleGene>
- Specified by:
newInstance
in interfaceGene<Double,DoubleGene>
- Parameters:
allele
- the value of the new gene.- Returns:
- a new gene with the given value.
-
newInstance
public DoubleGene newInstance(Number allele)
Description copied from interface:BoundedGene
Create a new gene from the givenvalue
and the current bounds.- Specified by:
newInstance
in interfaceNumericGene<Double,DoubleGene>
- Parameters:
allele
- the value of the new gene.- Returns:
- a new gene with the given value.
-
newInstance
public DoubleGene newInstance()
Description copied from interface:Gene
Return 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 theRandom
object which can be fetched from theRandomRegistry
.- Specified by:
newInstance
in interfaceFactory<DoubleGene>
- Specified by:
newInstance
in interfaceGene<Double,DoubleGene>
- Returns:
- a new instance of type T
-
of
public static DoubleGene of(double allele, double min, double max)
Create a new randomDoubleGene
with the given value and the given range. If thevalue
isn'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
DoubleGene
with the given parameter
-
of
public static DoubleGene of(double allele, DoubleRange range)
Create a new randomDoubleGene
with the given value and the given range. If thevalue
isn'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 double range to use- Returns:
- a new random
DoubleGene
- Throws:
NullPointerException
- if the givenrange
isnull
.- Since:
- 3.2
-
of
public static DoubleGene of(double min, double max)
Create a new randomDoubleGene
. It is guaranteed that the value of theDoubleGene
lies 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
DoubleGene
with the given parameter
-
of
public static DoubleGene of(DoubleRange range)
Create a new randomDoubleGene
. It is guaranteed that the value of theDoubleGene
lies in the interval [min, max).- Parameters:
range
- the double range to use- Returns:
- a new
DoubleGene
with the given parameter - Throws:
NullPointerException
- if the givenrange
isnull
.- Since:
- 3.2
-
-