java.lang.Object
io.jenetics.util.Conversions
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 Summary
Modifier and TypeMethodDescriptionstatic int[]doubleToIntArray(double[] array) Converts the givenlong[]arrayto adouble[]array.static int[]doubleToIntArray(double[] array, DoubleToIntFunction mapper) Converts the givendouble[]arrayto aint[]array.static Function<double[], int[]> doubleToIntArray(DoubleToIntFunction mapper) Return an array mapper function which applies the givenmapperto every array element.static long[]doubleToLongArray(double[] array) Converts the givenlong[]arrayto adouble[]array.static long[]doubleToLongArray(double[] array, DoubleToLongFunction mapper) Converts the givendouble[]arrayto along[]array.static Function<double[], long[]> Return an array mapper function which applies the givenmapperto every array element.static double[]intToDoubleArray(int[] array) Converts the givenint[]arrayto adouble[]array.static double[]intToDoubleArray(int[] array, IntToDoubleFunction mapper) Converts the givenint[]arrayto adouble[]array.static Function<int[], double[]> intToDoubleArray(IntToDoubleFunction mapper) Return an array mapper function which applies the givenmapperto every array element.static long[]intToLongArray(int[] array) Converts the givenint[]arrayto along[]array.static long[]intToLongArray(int[] array, IntToLongFunction mapper) Converts the givenint[]arrayto along[]array.static Function<int[], long[]> intToLongFunction(IntToLongFunction mapper) Return an array mapper function which applies the givenmapperto every array element.static double[]longToDoubleArray(long[] array) Converts the givenlong[]arrayto adouble[]array.static double[]longToDoubleArray(long[] array, LongToDoubleFunction mapper) Converts the givenlong[]arrayto adouble[]array.static Function<long[], double[]> Return an array mapper function which applies the givenmapperto every array element.static int[]longToIntArray(long[] array) Converts the givenlong[]arrayto aint[]array.static int[]longToIntArray(long[] array, LongToIntFunction mapper) Converts the givenlong[]arrayto aint[]array.static Function<long[], int[]> longToIntArray(LongToIntFunction mapper) Return an array mapper function which applies the givenmapperto every array element.
-
Method Details
-
intToLongArray
Converts the givenint[]arrayto along[]array.- Parameters:
array- the array to convertmapper- the mapper function applied to eacharrayelement- Returns:
- the converted array
-
intToLongFunction
Return an array mapper function which applies the givenmapperto every array element.- Parameters:
mapper- the array element mapper- Returns:
- an array mapper function
-
intToLongArray
Converts the givenint[]arrayto along[]array.- Parameters:
array- the array to convert- Returns:
- the converted array
-
intToDoubleArray
Converts the givenint[]arrayto adouble[]array.- Parameters:
array- the array to convertmapper- the mapper function applied to eacharrayelement- Returns:
- the converted array
-
intToDoubleArray
Return an array mapper function which applies the givenmapperto every array element.- Parameters:
mapper- the array element mapper- Returns:
- an array mapper function
-
intToDoubleArray
Converts the givenint[]arrayto adouble[]array.- Parameters:
array- the array to convert- Returns:
- the converted array
-
longToIntArray
Converts the givenlong[]arrayto aint[]array.- Parameters:
array- the array to convertmapper- the mapper function applied to eacharrayelement- Returns:
- the converted array
-
longToIntArray
Return an array mapper function which applies the givenmapperto every array element.- Parameters:
mapper- the array element mapper- Returns:
- an array mapper function
-
longToIntArray
Converts the givenlong[]arrayto aint[]array. Theint[]is filled with thelongvalues cast tointvalues.- Parameters:
array- the array to convert- Returns:
- the converted array
-
longToDoubleArray
Converts the givenlong[]arrayto adouble[]array.- Parameters:
array- the array to convertmapper- the mapper function applied to eacharrayelement- Returns:
- the converted array
-
longToDoubleArray
Return an array mapper function which applies the givenmapperto every array element.- Parameters:
mapper- the array element mapper- Returns:
- an array mapper function
-
longToDoubleArray
Converts the givenlong[]arrayto adouble[]array.- Parameters:
array- the array to convert- Returns:
- the converted array
-
doubleToIntArray
Converts the givendouble[]arrayto aint[]array.- Parameters:
array- the array to convertmapper- the mapper function applied to eacharrayelement- Returns:
- the converted array
-
doubleToIntArray
Return an array mapper function which applies the givenmapperto 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
Converts the givenlong[]arrayto adouble[]array. Theint[]is filled with thedoublevalues cast tointvalues.- Parameters:
array- the array to convert- Returns:
- the converted array
-
doubleToLongArray
Converts the givendouble[]arrayto along[]array.- Parameters:
array- the array to convertmapper- the mapper function applied to eacharrayelement- Returns:
- the converted array
-
doubleToLongArray
Return an array mapper function which applies the givenmapperto every array element.- Parameters:
mapper- the array element mapper- Returns:
- an array mapper function
-
doubleToLongArray
Converts the givenlong[]arrayto adouble[]array. Thelong[]is filled with thedoublevalues cast tolongvalues.- Parameters:
array- the array to convert- Returns:
- the converted array
-