Example usage for java.util.function DoubleFunction apply

List of usage examples for java.util.function DoubleFunction apply

Introduction

In this page you can find the example usage for java.util.function DoubleFunction apply.

Prototype

R apply(double value);

Source Link

Document

Applies this function to the given argument.

Usage

From source file:net.sf.mzmine.chartbasics.HistogramChartFactory.java

private static void addDPToSeries(XYSeries series, int[] bins, int i, double binwidth, double min, double max,
        DoubleFunction<Double> function) {
    // adds a data point to the series
    double x = min + (binwidth / 2.0) + i * binwidth;
    if (function != null)
        x = function.apply(x);
    series.add(x, bins[i]);/* w ww.j ava 2 s .  c  o m*/
}

From source file:net.sf.mzmine.chartbasics.HistogramChartFactory.java

private static void addDPToList(List<DataPoint> list, int[] bins, int i, double binwidth, double min,
        double max, DoubleFunction<Double> function) {
    // adds a data point to the series
    double x = min + (binwidth / 2.0) + i * binwidth;
    if (function != null)
        x = function.apply(x);
    list.add(new SimpleDataPoint(x, bins[i]));
}

From source file:bachelorthesis.methods.detection.bayesian.BayesianDetection.java

private double[] forEach(double[] values, DoubleFunction<Double> function) {
    double[] result = new double[values.length];
    for (int i = 0; i < values.length; i++) {
        result[i] = function.apply(values[i]);
    }//from w  w  w . j  a  v  a2  s  .  c  o  m
    return result;
}

From source file:net.sf.mzmine.chartbasics.HistogramChartFactory.java

public static JFreeChart createHistogram(double[] data, double binwidth, String yAxisLabel, double min,
        double max, DoubleFunction<Double> function) {
    if (data != null && data.length > 0) {
        double datawidth = (max - min);
        int cbin = (int) Math.ceil(datawidth / binwidth);
        int[] bins = new int[cbin + 1];

        XYSeries series = createHistoSeries(data, binwidth, min, max, function);
        double barwidth = binwidth;

        // calc new barwidth if a transformation function is defined
        if (function != null) {
            int sum = Arrays.stream(bins).sum();
            // see when 98% of the data is displayed
            int sum2 = 0;
            for (int i = 0; i < bins.length; i++) {
                if (bins[i] > 0) {
                    sum2 += bins[i];//from   www . j  a  v  a 2 s.com
                    if ((sum2 / (double) sum) >= 0.99) {
                        barwidth = function.apply(min + (binwidth / 2.0) + i * binwidth).doubleValue()
                                - function.apply(min + (binwidth / 2.0) + (i - 1) * binwidth).doubleValue();
                    }
                }
            }
        }
        return createHistogram(series, barwidth, yAxisLabel);
    } else
        return null;
}

From source file:at.gridtec.lambda4j.function.bi.to.ToDoubleBiFunction2.java

/**
 * Returns a composed {@link BiFunction2} that first applies this function to its input, and then applies the
 * {@code after} function to the result.
 * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation.
 *
 * @param <S> The type of return value from the {@code after} function, and of the composed function
 * @param after The function to apply after this function is applied
 * @return A composed {@code BiFunction2} that first applies this function to its input, and then applies the {@code
 * after} function to the result.//from w  ww . ja  va 2  s.  c o m
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to return every type.
 */
@Nonnull
default <S> BiFunction2<T, U, S> andThen(@Nonnull final DoubleFunction<? extends S> after) {
    Objects.requireNonNull(after);
    return (t, u) -> after.apply(applyAsDouble(t, u));
}

From source file:at.gridtec.lambda4j.function.tri.to.ToDoubleTriFunction.java

/**
 * Returns a composed {@link TriFunction} that first applies this function to its input, and then applies the
 * {@code after} function to the result.
 * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation.
 *
 * @param <S> The type of return value from the {@code after} function, and of the composed function
 * @param after The function to apply after this function is applied
 * @return A composed {@code TriFunction} that first applies this function to its input, and then applies the {@code
 * after} function to the result./*from www . j  av a  2 s  .  c  om*/
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to return every type.
 */
@Nonnull
default <S> TriFunction<T, U, V, S> andThen(@Nonnull final DoubleFunction<? extends S> after) {
    Objects.requireNonNull(after);
    return (t, u, v) -> after.apply(applyAsDouble(t, u, v));
}

From source file:at.gridtec.lambda4j.function.bi.conversion.BiBooleanToDoubleFunction.java

/**
 * Returns a composed {@link BiBooleanFunction} that first applies this function to its input, and then applies the
 * {@code after} function to the result.
 * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation.
 *
 * @param <S> The type of return value from the {@code after} function, and of the composed function
 * @param after The function to apply after this function is applied
 * @return A composed {@code BiBooleanFunction} that first applies this function to its input, and then applies the
 * {@code after} function to the result.
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to return every type.
 *///  w w  w  .jav a 2s .com
@Nonnull
default <S> BiBooleanFunction<S> andThen(@Nonnull final DoubleFunction<? extends S> after) {
    Objects.requireNonNull(after);
    return (value1, value2) -> after.apply(applyAsDouble(value1, value2));
}

From source file:at.gridtec.lambda4j.function.bi.conversion.BiByteToDoubleFunction.java

/**
 * Returns a composed {@link BiByteFunction} that first applies this function to its input, and then applies the
 * {@code after} function to the result.
 * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation.
 *
 * @param <S> The type of return value from the {@code after} function, and of the composed function
 * @param after The function to apply after this function is applied
 * @return A composed {@code BiByteFunction} that first applies this function to its input, and then applies the
 * {@code after} function to the result.
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to return every type.
 *///w w  w .j a v  a 2 s .  c  o m
@Nonnull
default <S> BiByteFunction<S> andThen(@Nonnull final DoubleFunction<? extends S> after) {
    Objects.requireNonNull(after);
    return (value1, value2) -> after.apply(applyAsDouble(value1, value2));
}

From source file:at.gridtec.lambda4j.function.bi.conversion.BiCharToDoubleFunction.java

/**
 * Returns a composed {@link BiCharFunction} that first applies this function to its input, and then applies the
 * {@code after} function to the result.
 * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation.
 *
 * @param <S> The type of return value from the {@code after} function, and of the composed function
 * @param after The function to apply after this function is applied
 * @return A composed {@code BiCharFunction} that first applies this function to its input, and then applies the
 * {@code after} function to the result.
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to return every type.
 *//*from   w  ww  . j ava2 s . c o m*/
@Nonnull
default <S> BiCharFunction<S> andThen(@Nonnull final DoubleFunction<? extends S> after) {
    Objects.requireNonNull(after);
    return (value1, value2) -> after.apply(applyAsDouble(value1, value2));
}

From source file:at.gridtec.lambda4j.function.bi.conversion.BiFloatToDoubleFunction.java

/**
 * Returns a composed {@link BiFloatFunction} that first applies this function to its input, and then applies the
 * {@code after} function to the result.
 * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation.
 *
 * @param <S> The type of return value from the {@code after} function, and of the composed function
 * @param after The function to apply after this function is applied
 * @return A composed {@code BiFloatFunction} that first applies this function to its input, and then applies the
 * {@code after} function to the result.
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to return every type.
 *//*from ww w  . j  a v a  2 s  . co  m*/
@Nonnull
default <S> BiFloatFunction<S> andThen(@Nonnull final DoubleFunction<? extends S> after) {
    Objects.requireNonNull(after);
    return (value1, value2) -> after.apply(applyAsDouble(value1, value2));
}