Java Code Examples for java.util.function.IntToDoubleFunction#applyAsDouble()
The following examples show how to use
java.util.function.IntToDoubleFunction#applyAsDouble() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PowerPanel.java From strongback-java with MIT License | 6 votes |
/** * Create a new PowerPanel from functions that supply the current for each channel, total current, voltage, and temperature. * * @param currentForChannel the function that returns the current for a given channel; may not be null * @param totalCurrent the function that returns total current; may not be null * @param voltage the function that returns voltage; may not be null * @param temperature the function that returns temperature; may not be null * @return the power panel; never null * @see Hardware#powerPanel() */ public static PowerPanel create(IntToDoubleFunction currentForChannel, DoubleSupplier totalCurrent, DoubleSupplier voltage, DoubleSupplier temperature) { return new PowerPanel() { @Override public CurrentSensor getCurrentSensor(int channel) { return () -> currentForChannel.applyAsDouble(channel); } @Override public CurrentSensor getTotalCurrentSensor() { return totalCurrent::getAsDouble; } @Override public VoltageSensor getVoltageSensor() { return voltage::getAsDouble; } @Override public TemperatureSensor getTemperatureSensor() { return voltage::getAsDouble; } }; }
Example 2
Source File: InputDevice.java From strongback-java with MIT License | 6 votes |
/** * Create an input device from the supplied mapping functions. * @param axisToValue the function that maps an integer to a double value for the axis * @param buttonNumberToSwitch the function that maps an integer to whether the button is pressed * @param padToValue the function that maps an integer to the directional axis output * @return the resulting input device; never null */ public static InputDevice create( IntToDoubleFunction axisToValue, IntToBooleanFunction buttonNumberToSwitch, IntToIntFunction padToValue ) { return new InputDevice() { @Override public ContinuousRange getAxis(int axis) { return ()->axisToValue.applyAsDouble(axis); } @Override public Switch getButton(int button) { return ()->buttonNumberToSwitch.applyAsBoolean(button); } @Override public DirectionalAxis getDPad(int pad) { return ()->padToValue.applyAsInt(pad); } }; }
Example 3
Source File: RandomVariableFromFloatArray.java From finmath-lib with Apache License 2.0 | 6 votes |
/** * Create a stochastic random variable. * * @param time the filtration time, set to 0.0 if not used. * @param realizations A map mapping integer (path or state) to double, representing this random variable. * @param size The size, i.e., number of paths. * @param typePriority The priority of this type in construction of result types. See "operator type priority" for details. */ public RandomVariableFromFloatArray(final double time, final IntToDoubleFunction realizations, final int size, final int typePriority) { super(); this.time = time; this.realizations = size == 1 ? null : new float[size];//IntStream.range(0,size).parallel().mapToDouble(realisations).toArray(); valueIfNonStochastic = size == 1 ? realizations.applyAsDouble(0) : Double.NaN; if(size > 1) { IntStream.range(0,size).parallel().forEach(new IntConsumer() { @Override public void accept(final int i) { RandomVariableFromFloatArray.this.realizations[i] = (float) realizations.applyAsDouble(i); } } ); } this.typePriority = typePriority; }
Example 4
Source File: RandomVariableFromDoubleArray.java From finmath-lib with Apache License 2.0 | 6 votes |
/** * Create a stochastic random variable. * * @param time the filtration time, set to 0.0 if not used. * @param realizations A map mapping integer (path or state) to double, representing this random variable. * @param size The size, i.e., number of paths. * @param typePriority The priority of this type in construction of result types. See "operator type priority" for details. */ public RandomVariableFromDoubleArray(final double time, final IntToDoubleFunction realizations, final int size, final int typePriority) { super(); this.time = time; this.realizations = size == 1 ? null : new double[size];//IntStream.range(0,size).parallel().mapToDouble(realisations).toArray(); valueIfNonStochastic = size == 1 ? realizations.applyAsDouble(0) : Double.NaN; if(size > 1) { IntStream.range(0,size).parallel().forEach(new IntConsumer() { @Override public void accept(final int i) { RandomVariableFromDoubleArray.this.realizations[i] = realizations.applyAsDouble(i); } } ); } this.typePriority = typePriority; }
Example 5
Source File: RandomVariableFromFloatArray.java From finmath-lib with Apache License 2.0 | 6 votes |
/** * Create a stochastic random variable. * * @param time the filtration time, set to 0.0 if not used. * @param realizations A map mapping integer (path or state) to double, representing this random variable. * @param size The size, i.e., number of paths. * @param typePriority The priority of this type in construction of result types. See "operator type priority" for details. */ public RandomVariableFromFloatArray(final double time, final IntToDoubleFunction realizations, final int size, final int typePriority) { super(); this.time = time; this.realizations = size == 1 ? null : new float[size];//IntStream.range(0,size).parallel().mapToDouble(realisations).toArray(); valueIfNonStochastic = size == 1 ? realizations.applyAsDouble(0) : Double.NaN; if(size > 1) { IntStream.range(0,size).parallel().forEach(new IntConsumer() { @Override public void accept(final int i) { RandomVariableFromFloatArray.this.realizations[i] = (float) realizations.applyAsDouble(i); } } ); } this.typePriority = typePriority; }
Example 6
Source File: RandomVariableFromDoubleArray.java From finmath-lib with Apache License 2.0 | 6 votes |
/** * Create a stochastic random variable. * * @param time the filtration time, set to 0.0 if not used. * @param realizations A map mapping integer (path or state) to double, representing this random variable. * @param size The size, i.e., number of paths. * @param typePriority The priority of this type in construction of result types. See "operator type priority" for details. */ public RandomVariableFromDoubleArray(final double time, final IntToDoubleFunction realizations, final int size, final int typePriority) { super(); this.time = time; this.realizations = size == 1 ? null : new double[size];//IntStream.range(0,size).parallel().mapToDouble(realisations).toArray(); valueIfNonStochastic = size == 1 ? realizations.applyAsDouble(0) : Double.NaN; if(size > 1) { IntStream.range(0,size).parallel().forEach(new IntConsumer() { @Override public void accept(final int i) { RandomVariableFromDoubleArray.this.realizations[i] = realizations.applyAsDouble(i); } } ); } this.typePriority = typePriority; }
Example 7
Source File: IndexRange.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Apply an int -> double function to this range, producing a double[] * * @param lambda the int -> double function */ public double[] mapToDouble(final IntToDoubleFunction lambda) { Utils.nonNull(lambda, "the lambda function cannot be null"); final double[] result = new double[size()]; for (int i = from; i < to; i++) { result[i - from] = lambda.applyAsDouble(i); } return result; }
Example 8
Source File: IndexRange.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Sums the values of an int -> double function applied to this range * * @param lambda the int -> double function */ public double sum(final IntToDoubleFunction lambda) { Utils.nonNull(lambda, "the lambda function cannot be null"); double result = 0; for (int i = from; i < to; i++) { result += lambda.applyAsDouble(i); } return result; }
Example 9
Source File: FlightStick.java From strongback-java with MIT License | 4 votes |
public static FlightStick create(IntToDoubleFunction axisToValue, IntToBooleanFunction buttonNumberToSwitch, IntToIntFunction padToValue, ContinuousRange pitch, ContinuousRange yaw, ContinuousRange roll, ContinuousRange throttle, Switch trigger, Switch thumb) { return new FlightStick() { @Override public ContinuousRange getAxis(int axis) { return () -> axisToValue.applyAsDouble(axis); } @Override public Switch getButton(int button) { return () -> buttonNumberToSwitch.applyAsBoolean(button); } @Override public DirectionalAxis getDPad(int pad) { return () -> padToValue.applyAsInt(pad); } @Override public ContinuousRange getPitch() { return pitch; } @Override public ContinuousRange getYaw() { return yaw; } @Override public ContinuousRange getRoll() { return roll; } @Override public ContinuousRange getThrottle() { return throttle; } @Override public Switch getTrigger() { return trigger; } @Override public Switch getThumb() { return thumb; } }; }
Example 10
Source File: DesugarArrays.java From desugar_jdk_libs with GNU General Public License v2.0 | 2 votes |
/** * Set all elements of the specified array, using the provided * generator function to compute each element. * * <p>If the generator function throws an exception, it is relayed to * the caller and the array is left in an indeterminate state. * * @param array array to be initialized * @param generator a function accepting an index and producing the desired * value for that position * @throws NullPointerException if the generator is null * @since 1.8 */ public static void setAll(double[] array, IntToDoubleFunction generator) { Objects.requireNonNull(generator); for (int i = 0; i < array.length; i++) array[i] = generator.applyAsDouble(i); }