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[]
array
to adouble[]
array.static int[]
doubleToIntArray
(double[] array, DoubleToIntFunction mapper) Converts the givendouble[]
array
to aint[]
array.static Function
<double[], int[]> doubleToIntArray
(DoubleToIntFunction mapper) Return an array mapper function which applies the givenmapper
to every array element.static long[]
doubleToLongArray
(double[] array) Converts the givenlong[]
array
to adouble[]
array.static long[]
doubleToLongArray
(double[] array, DoubleToLongFunction mapper) Converts the givendouble[]
array
to along[]
array.static Function
<double[], long[]> Return an array mapper function which applies the givenmapper
to every array element.static double[]
intToDoubleArray
(int[] array) Converts the givenint[]
array
to adouble[]
array.static double[]
intToDoubleArray
(int[] array, IntToDoubleFunction mapper) Converts the givenint[]
array
to adouble[]
array.static Function
<int[], double[]> intToDoubleArray
(IntToDoubleFunction mapper) Return an array mapper function which applies the givenmapper
to every array element.static long[]
intToLongArray
(int[] array) Converts the givenint[]
array
to along[]
array.static long[]
intToLongArray
(int[] array, IntToLongFunction mapper) Converts the givenint[]
array
to along[]
array.static Function
<int[], long[]> intToLongFunction
(IntToLongFunction mapper) Return an array mapper function which applies the givenmapper
to every array element.static double[]
longToDoubleArray
(long[] array) Converts the givenlong[]
array
to adouble[]
array.static double[]
longToDoubleArray
(long[] array, LongToDoubleFunction mapper) Converts the givenlong[]
array
to adouble[]
array.static Function
<long[], double[]> Return an array mapper function which applies the givenmapper
to every array element.static int[]
longToIntArray
(long[] array) Converts the givenlong[]
array
to aint[]
array.static int[]
longToIntArray
(long[] array, LongToIntFunction mapper) Converts the givenlong[]
array
to aint[]
array.static Function
<long[], int[]> longToIntArray
(LongToIntFunction mapper) Return an array mapper function which applies the givenmapper
to every array element.
-
Method Details
-
intToLongArray
Converts the givenint[]
array
to along[]
array.- Parameters:
array
- the array to convertmapper
- the mapper function applied to eacharray
element- Returns:
- the converted array
-
intToLongFunction
Return an array mapper function which applies the givenmapper
to every array element.- Parameters:
mapper
- the array element mapper- Returns:
- an array mapper function
-
intToLongArray
Converts the givenint[]
array
to along[]
array.- Parameters:
array
- the array to convert- Returns:
- the converted array
-
intToDoubleArray
Converts the givenint[]
array
to adouble[]
array.- Parameters:
array
- the array to convertmapper
- the mapper function applied to eacharray
element- Returns:
- the converted array
-
intToDoubleArray
Return an array mapper function which applies the givenmapper
to every array element.- Parameters:
mapper
- the array element mapper- Returns:
- an array mapper function
-
intToDoubleArray
Converts the givenint[]
array
to adouble[]
array.- Parameters:
array
- the array to convert- Returns:
- the converted array
-
longToIntArray
Converts the givenlong[]
array
to aint[]
array.- Parameters:
array
- the array to convertmapper
- the mapper function applied to eacharray
element- Returns:
- the converted array
-
longToIntArray
Return an array mapper function which applies the givenmapper
to every array element.- Parameters:
mapper
- the array element mapper- Returns:
- an array mapper function
-
longToIntArray
Converts the givenlong[]
array
to aint[]
array. Theint[]
is filled with thelong
values cast toint
values.- Parameters:
array
- the array to convert- Returns:
- the converted array
-
longToDoubleArray
Converts the givenlong[]
array
to adouble[]
array.- Parameters:
array
- the array to convertmapper
- the mapper function applied to eacharray
element- Returns:
- the converted array
-
longToDoubleArray
Return an array mapper function which applies the givenmapper
to every array element.- Parameters:
mapper
- the array element mapper- Returns:
- an array mapper function
-
longToDoubleArray
Converts the givenlong[]
array
to adouble[]
array.- Parameters:
array
- the array to convert- Returns:
- the converted array
-
doubleToIntArray
Converts the givendouble[]
array
to aint[]
array.- Parameters:
array
- the array to convertmapper
- the mapper function applied to eacharray
element- Returns:
- the converted array
-
doubleToIntArray
Return an array mapper function which applies the givenmapper
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
Converts the givenlong[]
array
to adouble[]
array. Theint[]
is filled with thedouble
values cast toint
values.- Parameters:
array
- the array to convert- Returns:
- the converted array
-
doubleToLongArray
Converts the givendouble[]
array
to along[]
array.- Parameters:
array
- the array to convertmapper
- the mapper function applied to eacharray
element- Returns:
- the converted array
-
doubleToLongArray
Return an array mapper function which applies the givenmapper
to every array element.- Parameters:
mapper
- the array element mapper- Returns:
- an array mapper function
-
doubleToLongArray
Converts the givenlong[]
array
to adouble[]
array. Thelong[]
is filled with thedouble
values cast tolong
values.- Parameters:
array
- the array to convert- Returns:
- the converted array
-