Example usage for java.util.function ToDoubleFunction applyAsDouble

List of usage examples for java.util.function ToDoubleFunction applyAsDouble

Introduction

In this page you can find the example usage for java.util.function ToDoubleFunction applyAsDouble.

Prototype

double applyAsDouble(T value);

Source Link

Document

Applies this function to the given argument.

Usage

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjDoubleToDoubleFunction.java

/**
 * Creates a {@link BiObjDoubleToDoubleFunction} which uses the {@code first} parameter of this one as argument for
 * the given {@link ToDoubleFunction}./*  w  w  w.jav a2s.  c  o m*/
 *
 * @param <T> The type of the first argument to the function
 * @param <U> The type of the second argument to the function
 * @param function The function which accepts the {@code first} parameter of this one
 * @return Creates a {@code BiObjDoubleToDoubleFunction} which uses the {@code first} parameter of this one as
 * argument for the given {@code ToDoubleFunction}.
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
static <T, U> BiObjDoubleToDoubleFunction<T, U> onlyFirst(@Nonnull final ToDoubleFunction<? super T> function) {
    Objects.requireNonNull(function);
    return (t, u, value) -> function.applyAsDouble(t);
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjIntToDoubleFunction.java

/**
 * Creates a {@link BiObjIntToDoubleFunction} which uses the {@code first} parameter of this one as argument for the
 * given {@link ToDoubleFunction}./*from  w w w  .j av a 2 s .  c  om*/
 *
 * @param <T> The type of the first argument to the function
 * @param <U> The type of the second argument to the function
 * @param function The function which accepts the {@code first} parameter of this one
 * @return Creates a {@code BiObjIntToDoubleFunction} which uses the {@code first} parameter of this one as argument
 * for the given {@code ToDoubleFunction}.
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
static <T, U> BiObjIntToDoubleFunction<T, U> onlyFirst(@Nonnull final ToDoubleFunction<? super T> function) {
    Objects.requireNonNull(function);
    return (t, u, value) -> function.applyAsDouble(t);
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjIntToDoubleFunction.java

/**
 * Creates a {@link BiObjIntToDoubleFunction} which uses the {@code second} parameter of this one as argument for
 * the given {@link ToDoubleFunction}./*w  ww.  j  a v  a2s.c  o m*/
 *
 * @param <T> The type of the first argument to the function
 * @param <U> The type of the second argument to the function
 * @param function The function which accepts the {@code second} parameter of this one
 * @return Creates a {@code BiObjIntToDoubleFunction} which uses the {@code second} parameter of this one as
 * argument for the given {@code ToDoubleFunction}.
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
static <T, U> BiObjIntToDoubleFunction<T, U> onlySecond(@Nonnull final ToDoubleFunction<? super U> function) {
    Objects.requireNonNull(function);
    return (t, u, value) -> function.applyAsDouble(u);
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjLongToDoubleFunction.java

/**
 * Creates a {@link BiObjLongToDoubleFunction} which uses the {@code first} parameter of this one as argument for
 * the given {@link ToDoubleFunction}./*from  w w w. j a va2  s.  co  m*/
 *
 * @param <T> The type of the first argument to the function
 * @param <U> The type of the second argument to the function
 * @param function The function which accepts the {@code first} parameter of this one
 * @return Creates a {@code BiObjLongToDoubleFunction} which uses the {@code first} parameter of this one as
 * argument for the given {@code ToDoubleFunction}.
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
static <T, U> BiObjLongToDoubleFunction<T, U> onlyFirst(@Nonnull final ToDoubleFunction<? super T> function) {
    Objects.requireNonNull(function);
    return (t, u, value) -> function.applyAsDouble(t);
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjLongToDoubleFunction.java

/**
 * Creates a {@link BiObjLongToDoubleFunction} which uses the {@code second} parameter of this one as argument for
 * the given {@link ToDoubleFunction}./* ww w  .  j  av a2 s  .c  om*/
 *
 * @param <T> The type of the first argument to the function
 * @param <U> The type of the second argument to the function
 * @param function The function which accepts the {@code second} parameter of this one
 * @return Creates a {@code BiObjLongToDoubleFunction} which uses the {@code second} parameter of this one as
 * argument for the given {@code ToDoubleFunction}.
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
static <T, U> BiObjLongToDoubleFunction<T, U> onlySecond(@Nonnull final ToDoubleFunction<? super U> function) {
    Objects.requireNonNull(function);
    return (t, u, value) -> function.applyAsDouble(u);
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjDoubleToDoubleFunction.java

/**
 * Creates a {@link BiObjDoubleToDoubleFunction} which uses the {@code second} parameter of this one as argument for
 * the given {@link ToDoubleFunction}.//from w  w w  .j av  a  2  s  .  c o  m
 *
 * @param <T> The type of the first argument to the function
 * @param <U> The type of the second argument to the function
 * @param function The function which accepts the {@code second} parameter of this one
 * @return Creates a {@code BiObjDoubleToDoubleFunction} which uses the {@code second} parameter of this one as
 * argument for the given {@code ToDoubleFunction}.
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
static <T, U> BiObjDoubleToDoubleFunction<T, U> onlySecond(
        @Nonnull final ToDoubleFunction<? super U> function) {
    Objects.requireNonNull(function);
    return (t, u, value) -> function.applyAsDouble(u);
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjBooleanToDoubleFunction.java

/**
 * Creates a {@link BiObjBooleanToDoubleFunction} which uses the {@code first} parameter of this one as argument for
 * the given {@link ToDoubleFunction}./*from w ww.  j a v  a 2s .c  om*/
 *
 * @param <T> The type of the first argument to the function
 * @param <U> The type of the second argument to the function
 * @param function The function which accepts the {@code first} parameter of this one
 * @return Creates a {@code BiObjBooleanToDoubleFunction} which uses the {@code first} parameter of this one as
 * argument for the given {@code ToDoubleFunction}.
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
static <T, U> BiObjBooleanToDoubleFunction<T, U> onlyFirst(
        @Nonnull final ToDoubleFunction<? super T> function) {
    Objects.requireNonNull(function);
    return (t, u, value) -> function.applyAsDouble(t);
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjBooleanToDoubleFunction.java

/**
 * Creates a {@link BiObjBooleanToDoubleFunction} which uses the {@code second} parameter of this one as argument
 * for the given {@link ToDoubleFunction}.
 *
 * @param <T> The type of the first argument to the function
 * @param <U> The type of the second argument to the function
 * @param function The function which accepts the {@code second} parameter of this one
 * @return Creates a {@code BiObjBooleanToDoubleFunction} which uses the {@code second} parameter of this one as
 * argument for the given {@code ToDoubleFunction}.
 * @throws NullPointerException If given argument is {@code null}
 *//*w w w  .j a v a 2  s. c  o  m*/
@Nonnull
static <T, U> BiObjBooleanToDoubleFunction<T, U> onlySecond(
        @Nonnull final ToDoubleFunction<? super U> function) {
    Objects.requireNonNull(function);
    return (t, u, value) -> function.applyAsDouble(u);
}

From source file:de.bund.bfr.math.MathUtils.java

public static List<StartValues> createStartValuesList(List<ParamRange> ranges, int n,
        ToDoubleFunction<List<Double>> errorFunction, DoubleConsumer progessListener, ExecutionContext exec)
        throws CanceledExecutionException {
    List<StartValues> valuesList = new ArrayList<>();

    for (int i = 0; i < n; i++) {
        valuesList.add(new StartValues(Collections.nCopies(ranges.size(), i + 1.0), Double.POSITIVE_INFINITY));
    }//from ww w.j a v a2  s . c  o  m

    List<Integer> paramStepIndex = new ArrayList<>(Collections.nCopies(ranges.size(), 0));
    boolean done = false;
    int allStepSize = 1;
    int count = 0;

    for (ParamRange range : ranges) {
        allStepSize *= range.getStepCount();
    }

    while (!done) {
        List<Double> values = new ArrayList<>();

        for (int i = 0; i < ranges.size(); i++) {
            values.add(ranges.get(i).getMin() + paramStepIndex.get(i) * ranges.get(i).getStepSize());
        }

        double error = errorFunction.applyAsDouble(values);

        if (Double.isFinite(error) || error < valuesList.get(n - 1).getError()) {
            for (int i = 0; i < n; i++) {
                if (error < valuesList.get(i).getError()) {
                    valuesList.add(i, new StartValues(values, error));
                    valuesList.remove(n);
                    break;
                }
            }
        }

        for (int i = 0;; i++) {
            if (i >= ranges.size()) {
                done = true;
                break;
            }

            paramStepIndex.set(i, paramStepIndex.get(i) + 1);

            if (paramStepIndex.get(i) >= ranges.get(i).getStepCount()) {
                paramStepIndex.set(i, 0);
            } else {
                break;
            }
        }

        if (exec != null) {
            exec.checkCanceled();
        }

        progessListener.accept((double) ++count / (double) allStepSize);
    }

    return valuesList;
}

From source file:at.gridtec.lambda4j.function.bi.obj.ObjDoubleFunction.java

/**
 * Returns a composed {@link BiFunction2} that first applies the {@code before} functions to its input, and
 * then applies this function to the result.
 * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation.
 *
 * @param <A> The type of the argument to the first given function, and of composed function
 * @param <B> The type of the argument to the second given function, and of composed function
 * @param before1 The first function to apply before this function is applied
 * @param before2 The second function to apply before this function is applied
 * @return A composed {@code BiFunction2} that first applies the {@code before} functions to its input, and then
 * applies this function to the result./*from   w w w.  j  ava 2 s  .c o  m*/
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to handle every type.
 */
@Nonnull
default <A, B> BiFunction2<A, B, R> compose(@Nonnull final Function<? super A, ? extends T> before1,
        @Nonnull final ToDoubleFunction<? super B> before2) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    return (a, b) -> apply(before1.apply(a), before2.applyAsDouble(b));
}