Class Conversions

java.lang.Object
io.jenetics.util.Conversions

public class Conversions extends Object
This class contains methods for converting from and to the primitive arrays int[], long[] and double[]. Its main usage is to unify numerical gene codecs, e.g.:
 final Codec<int[], DoubleGene> codec = Codecs
     .ofVector(DoubleRange.of(0, 100), 100)
     .map(Conversions::doubleToIntArray);
Since:
8.1
Version:
8.1
  • Method Details

    • intToLongArray

      public static long[] intToLongArray(int[] array, IntToLongFunction mapper)
      Converts the given int[] array to a long[] array.
      Parameters:
      array - the array to convert
      mapper - the mapper function applied to each array element
      Returns:
      the converted array
    • intToLongFunction

      public static Function<int[],long[]> intToLongFunction(IntToLongFunction mapper)
      Return an array mapper function which applies the given mapper to every array element.
      Parameters:
      mapper - the array element mapper
      Returns:
      an array mapper function
    • intToLongArray

      public static long[] intToLongArray(int[] array)
      Converts the given int[] array to a long[] array.
      Parameters:
      array - the array to convert
      Returns:
      the converted array
    • intToDoubleArray

      public static double[] intToDoubleArray(int[] array, IntToDoubleFunction mapper)
      Converts the given int[] array to a double[] array.
      Parameters:
      array - the array to convert
      mapper - the mapper function applied to each array element
      Returns:
      the converted array
    • intToDoubleArray

      public static Function<int[],double[]> intToDoubleArray(IntToDoubleFunction mapper)
      Return an array mapper function which applies the given mapper to every array element.
      Parameters:
      mapper - the array element mapper
      Returns:
      an array mapper function
    • intToDoubleArray

      public static double[] intToDoubleArray(int[] array)
      Converts the given int[] array to a double[] array.
      Parameters:
      array - the array to convert
      Returns:
      the converted array
    • longToIntArray

      public static int[] longToIntArray(long[] array, LongToIntFunction mapper)
      Converts the given long[] array to a int[] array.
      Parameters:
      array - the array to convert
      mapper - the mapper function applied to each array element
      Returns:
      the converted array
    • longToIntArray

      public static Function<long[],int[]> longToIntArray(LongToIntFunction mapper)
      Return an array mapper function which applies the given mapper to every array element.
      Parameters:
      mapper - the array element mapper
      Returns:
      an array mapper function
    • longToIntArray

      public static int[] longToIntArray(long[] array)
      Converts the given long[] array to a int[] array. The int[] is filled with the long values cast to int values.
      Parameters:
      array - the array to convert
      Returns:
      the converted array
    • longToDoubleArray

      public static double[] longToDoubleArray(long[] array, LongToDoubleFunction mapper)
      Converts the given long[] array to a double[] array.
      Parameters:
      array - the array to convert
      mapper - the mapper function applied to each array element
      Returns:
      the converted array
    • longToDoubleArray

      public static Function<long[],double[]> longToDoubleArray(LongToDoubleFunction mapper)
      Return an array mapper function which applies the given mapper to every array element.
      Parameters:
      mapper - the array element mapper
      Returns:
      an array mapper function
    • longToDoubleArray

      public static double[] longToDoubleArray(long[] array)
      Converts the given long[] array to a double[] array.
      Parameters:
      array - the array to convert
      Returns:
      the converted array
    • doubleToIntArray

      public static int[] doubleToIntArray(double[] array, DoubleToIntFunction mapper)
      Converts the given double[] array to a int[] array.
      Parameters:
      array - the array to convert
      mapper - the mapper function applied to each array element
      Returns:
      the converted array
    • doubleToIntArray

      public static Function<double[],int[]> doubleToIntArray(DoubleToIntFunction mapper)
      Return an array mapper function which applies the given mapper to every array element.
       final Codec<int[], DoubleGene> codec = Codecs
           .ofVector(DoubleRange.of(0, 100), 100)
           .map(Conversions.doubleToIntArray(v -> (int)Math.round(v)));
      
      Parameters:
      mapper - the array element mapper
      Returns:
      an array mapper function
    • doubleToIntArray

      public static int[] doubleToIntArray(double[] array)
      Converts the given long[] array to a double[] array. The int[] is filled with the double values cast to int values.
      Parameters:
      array - the array to convert
      Returns:
      the converted array
    • doubleToLongArray

      public static long[] doubleToLongArray(double[] array, DoubleToLongFunction mapper)
      Converts the given double[] array to a long[] array.
      Parameters:
      array - the array to convert
      mapper - the mapper function applied to each array element
      Returns:
      the converted array
    • doubleToLongArray

      public static Function<double[],long[]> doubleToLongArray(DoubleToLongFunction mapper)
      Return an array mapper function which applies the given mapper to every array element.
      Parameters:
      mapper - the array element mapper
      Returns:
      an array mapper function
    • doubleToLongArray

      public static long[] doubleToLongArray(double[] array)
      Converts the given long[] array to a double[] array. The long[] is filled with the double values cast to long values.
      Parameters:
      array - the array to convert
      Returns:
      the converted array