Package io.jenetics

Class IntegerGene

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>

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 Details

    • allele

      public Integer allele()
      Description copied from interface: Gene
      Return the allele of this gene.
      Specified by:
      allele in interface Gene<Integer,IntegerGene>
      Returns:
      the allele of this gene.
    • min

      public Integer min()
      Description copied from interface: BoundedGene
      Return the allowed min value.
      Specified by:
      min in interface BoundedGene<Integer,IntegerGene>
      Returns:
      The allowed min value.
    • max

      public Integer max()
      Description copied from interface: BoundedGene
      Return the allowed max value.
      Specified by:
      max in interface BoundedGene<Integer,IntegerGene>
      Returns:
      The allowed max value.
    • range

      public IntRange range()
      Return the range of this 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 a byte. This may involve rounding or truncation.
      Specified by:
      byteValue in interface NumericGene<Integer,IntegerGene>
      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 a short. This may involve rounding or truncation.
      Specified by:
      shortValue in interface NumericGene<Integer,IntegerGene>
      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 interface NumericGene<Integer,IntegerGene>
      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 a long. This may involve rounding or truncation.
      Specified by:
      longValue in interface NumericGene<Integer,IntegerGene>
      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 a float. This may involve rounding or truncation.
      Specified by:
      floatValue in interface NumericGene<Integer,IntegerGene>
      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 a double. This may involve rounding or truncation.
      Specified by:
      doubleValue in interface NumericGene<Integer,IntegerGene>
      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 interface BoundedGene<Integer,IntegerGene>
      Specified by:
      isValid in interface Verifiable
      Returns:
      true if this object is valid, false otherwise.
    • compareTo

      public int compareTo(IntegerGene other)
      Specified by:
      compareTo in interface BoundedGene<Integer,IntegerGene>
      Specified by:
      compareTo in interface Comparable<IntegerGene>
    • mean

      public IntegerGene mean(IntegerGene that)
      Description copied from interface: Mean
      Return the (usually arithmetic) mean value of this and that. For NumericGenes the mean is the arithmetic mean.
      Specified by:
      mean in interface Mean<IntegerGene>
      Parameters:
      that - the second value for calculating the mean.
      Returns:
      the mean value of this and that.
    • newInstance

      public IntegerGene newInstance(int allele)
      Create a new gene from the given value 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 IntegerGene newInstance(Integer allele)
      Description copied from interface: BoundedGene
      Create a new gene from the given value and the current bounds.
      Specified by:
      newInstance in interface BoundedGene<Integer,IntegerGene>
      Specified by:
      newInstance in interface Gene<Integer,IntegerGene>
      Parameters:
      allele - the value of the new gene.
      Returns:
      a new gene with the given value.
    • newInstance

      public IntegerGene newInstance(Number allele)
      Description copied from interface: BoundedGene
      Create a new gene from the given value and the current bounds.
      Specified by:
      newInstance in interface NumericGene<Integer,IntegerGene>
      Parameters:
      allele - the value of the new gene.
      Returns:
      a new gene with the given value.
    • 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 holds gene.getClass() == gene.newInstance().getClass(). Implementations of this method have to use the RandomGenerator object which can be fetched from the RandomRegistry.
      Specified by:
      newInstance in interface Factory<IntegerGene>
      Specified by:
      newInstance in interface Gene<Integer,IntegerGene>
      Returns:
      a new instance of type T
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • of

      public static IntegerGene of(int allele, int min, int max)
      Create a new random IntegerGene with the given value and the given range. If the value isn't within the interval [min, max), no exception is thrown. In this case the method isValid() returns false.
      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 IntegerGene with the given value
    • of

      public static IntegerGene of(int allele, IntRange range)
      Create a new random IntegerGene with the given value and the given range. If the value isn't within the interval [min, max], no exception is thrown. In this case the method isValid() returns false.
      Parameters:
      allele - the value of the gene.
      range - the integer range to use
      Returns:
      a new IntegerGene with the give value
      Throws:
      NullPointerException - if the given range is null.
      Since:
      3.2
    • of

      public static IntegerGene of(int min, int max)
      Create a new random IntegerGene. It is guaranteed that the value of the IntegerGene 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 random IntegerGene
      Throws:
      IllegalArgumentException - if max is greater than or equal to min
    • of

      public static IntegerGene of(IntRange range)
      Create a new random IntegerGene. It is guaranteed that the value of the IntegerGene lies in the interval [min, max).
      Parameters:
      range - the integer range to use
      Returns:
      a new random IntegerGene
      Throws:
      NullPointerException - if the given range is null.
      IllegalArgumentException - if max is greater than or equal to min
      Since:
      3.2