Package io.jenetics
Class LongGene
- java.lang.Object
-
- io.jenetics.LongGene
-
- All Implemented Interfaces:
BoundedGene<Long,LongGene>,Gene<Long,LongGene>,NumericGene<Long,LongGene>,Factory<LongGene>,Mean<LongGene>,Verifiable,Serializable,Comparable<LongGene>
public final class LongGene extends Object implements NumericGene<Long,LongGene>, Mean<LongGene>, Comparable<LongGene>, Serializable
NumericGene implementation which holds a 64 bit integer number.This is a value-based class; use of identity-sensitive operations (including reference equality (
==), identity hash code, or synchronization) on instances ofLongGenemay have unpredictable results and should be avoided.- Since:
- 1.6
- Version:
- 6.1
- See Also:
LongChromosome, 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 Longallele()Return the allele of this gene.bytebyteValue()Returns the value of the specified gene as an byte.intcompareTo(LongGene other)doubledoubleValue()Returns the value of the specified gene as an double.booleanequals(Object obj)floatfloatValue()Returns the value of the specified gene as an float.inthashCode()intintValue()Returns the value of the specified gene as an int.booleanisValid()Check if this object is valid.longlongValue()Returns the value of the specified gene as an long.Longmax()Return the allowed max value.LongGenemean(LongGene that)Return the (usually arithmetic) mean value ofthisandthat.Longmin()Return the allowed min value.LongGenenewInstance()Return a new, random gene with the same type and with the same constraints than this gene.LongGenenewInstance(long allele)Create a new gene from the givenvalueand the gene context.LongGenenewInstance(Long allele)Create a new gene from the givenvalueand the current bounds.LongGenenewInstance(Number allele)Create a new gene from the givenvalueand the current bounds.static LongGeneof(long min, long max)Create a new randomLongGene.static LongGeneof(long allele, long min, long max)Create a new randomLongGenewith the given value and the given range.static LongGeneof(long allele, LongRange range)Create a new randomLongGenewith the given value and the given range.static LongGeneof(LongRange range)Create a new randomLongGene.LongRangerange()Return the range ofthisgene.shortshortValue()Returns the value of the specified gene as an short.StringtoString()
-
-
-
Method Detail
-
min
public Long min()
Description copied from interface:BoundedGeneReturn the allowed min value.- Specified by:
minin interfaceBoundedGene<Long,LongGene>- Returns:
- The allowed min value.
-
max
public Long max()
Description copied from interface:BoundedGeneReturn the allowed max value.- Specified by:
maxin interfaceBoundedGene<Long,LongGene>- Returns:
- The allowed max value.
-
range
public LongRange range()
Return the range ofthisgene.- Returns:
- the range of
thisgene - Since:
- 4.4
-
byteValue
public byte byteValue()
Description copied from interface:NumericGeneReturns the value of the specified gene as an byte. This may involve rounding or truncation.- Specified by:
byteValuein interfaceNumericGene<Long,LongGene>- Returns:
- the numeric value represented by this object after conversion to
type
byte.
-
shortValue
public short shortValue()
Description copied from interface:NumericGeneReturns the value of the specified gene as an short. This may involve rounding or truncation.- Specified by:
shortValuein interfaceNumericGene<Long,LongGene>- Returns:
- the numeric value represented by this object after conversion to
type
short.
-
intValue
public int 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<Long,LongGene>- Returns:
- the numeric value represented by this object after conversion to
type
int.
-
longValue
public long longValue()
Description copied from interface:NumericGeneReturns the value of the specified gene as an long. This may involve rounding or truncation.- Specified by:
longValuein interfaceNumericGene<Long,LongGene>- Returns:
- the numeric value represented by this object after conversion to
type
long.
-
floatValue
public float floatValue()
Description copied from interface:NumericGeneReturns the value of the specified gene as an float. This may involve rounding or truncation.- Specified by:
floatValuein interfaceNumericGene<Long,LongGene>- Returns:
- the numeric value represented by this object after conversion to
type
float.
-
doubleValue
public double doubleValue()
Description copied from interface:NumericGeneReturns the value of the specified gene as an double. This may involve rounding or truncation.- Specified by:
doubleValuein interfaceNumericGene<Long,LongGene>- Returns:
- the numeric value represented by this object after conversion to
type
double.
-
isValid
public boolean isValid()
Description copied from interface:VerifiableCheck if this object is valid.- Specified by:
isValidin interfaceBoundedGene<Long,LongGene>- Specified by:
isValidin interfaceVerifiable- Returns:
- true if this object is valid, false otherwise.
-
compareTo
public int compareTo(LongGene other)
- Specified by:
compareToin interfaceBoundedGene<Long,LongGene>- Specified by:
compareToin interfaceComparable<LongGene>
-
mean
public LongGene mean(LongGene that)
Description copied from interface:MeanReturn the (usually arithmetic) mean value ofthisandthat. ForNumericGenes the mean is the arithmetic mean.
-
newInstance
public LongGene newInstance(long allele)
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
public LongGene newInstance(Long allele)
Description copied from interface:BoundedGeneCreate a new gene from the givenvalueand the current bounds.- Specified by:
newInstancein interfaceBoundedGene<Long,LongGene>- Specified by:
newInstancein interfaceGene<Long,LongGene>- Parameters:
allele- the value of the new gene.- Returns:
- a new gene with the given value.
-
newInstance
public LongGene newInstance(Number allele)
Description copied from interface:BoundedGeneCreate a new gene from the givenvalueand the current bounds.- Specified by:
newInstancein interfaceNumericGene<Long,LongGene>- Parameters:
allele- the value of the new gene.- Returns:
- a new gene with the given value.
-
newInstance
public LongGene 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<LongGene>- Specified by:
newInstancein interfaceGene<Long,LongGene>- Returns:
- a new instance of type T
-
of
public static LongGene of(long allele, long min, long max)
Create a new randomLongGenewith 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 (inclusively).- Returns:
- a new
LongGenewith the given parameters.
-
of
public static LongGene of(long allele, LongRange range)
Create a new randomLongGenewith 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 long range to use- Returns:
- a new random
LongGene - Throws:
NullPointerException- if the givenrangeisnull.- Since:
- 3.2
-
of
public static LongGene of(long min, long max)
Create a new randomLongGene. It is guaranteed that the value of theLongGenelies in the interval [min, max].- Parameters:
min- the minimal valid value of this gene (inclusively).max- the maximal valid value of this gene (inclusively).- Returns:
- a new
LongGenewith the given parameters.
-
of
public static LongGene of(LongRange range)
Create a new randomLongGene. It is guaranteed that the value of theLongGenelies in the interval [min, max].- Parameters:
range- the long range to use- Returns:
- a new random
LongGene - Throws:
NullPointerException- if the givenrangeisnull.- Since:
- 3.2
-
-