类java.util.function.DoubleBinaryOperator源码实例Demo

下面列出了怎么用java.util.function.DoubleBinaryOperator的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: TencentKona-8   文件: PrimitiveSumMinMaxTest.java
public void testDoubleMethods() {
    BinaryOperator<Double> sum1 = Double::sum;
    DoubleBinaryOperator sum2 = Double::sum;
    BinaryOperator<Double> max1 = Double::max;
    DoubleBinaryOperator max2 = Double::max;
    BinaryOperator<Double> min1 = Double::min;
    DoubleBinaryOperator min2 = Double::min;
    Comparator<Double> cmp = Double::compare;

    double[] numbers = { -1, 0, 1, 100, Double.MAX_VALUE, Double.MIN_VALUE };
    for (double i : numbers) {
        for (double j : numbers) {
            assertEquals(i+j, (double) sum1.apply(i, j));
            assertEquals(i+j, sum2.applyAsDouble(i, j));
            assertEquals(Math.max(i,j), (double) max1.apply(i, j));
            assertEquals(Math.max(i,j), max2.applyAsDouble(i, j));
            assertEquals(Math.min(i,j), (double) min1.apply(i, j));
            assertEquals(Math.min(i,j), min2.applyAsDouble(i, j));
            assertEquals(((Double) i).compareTo(j), cmp.compare(i, j));
        }
    }
}
 
public void testDoubleMethods() {
    BinaryOperator<Double> sum1 = Double::sum;
    DoubleBinaryOperator sum2 = Double::sum;
    BinaryOperator<Double> max1 = Double::max;
    DoubleBinaryOperator max2 = Double::max;
    BinaryOperator<Double> min1 = Double::min;
    DoubleBinaryOperator min2 = Double::min;
    Comparator<Double> cmp = Double::compare;

    double[] numbers = { -1, 0, 1, 100, Double.MAX_VALUE, Double.MIN_VALUE };
    for (double i : numbers) {
        for (double j : numbers) {
            assertEquals(i+j, (double) sum1.apply(i, j));
            assertEquals(i+j, sum2.applyAsDouble(i, j));
            assertEquals(Math.max(i,j), (double) max1.apply(i, j));
            assertEquals(Math.max(i,j), max2.applyAsDouble(i, j));
            assertEquals(Math.min(i,j), (double) min1.apply(i, j));
            assertEquals(Math.min(i,j), min2.applyAsDouble(i, j));
            assertEquals(((Double) i).compareTo(j), cmp.compare(i, j));
        }
    }
}
 
源代码3 项目: jdk8u60   文件: PrimitiveSumMinMaxTest.java
public void testDoubleMethods() {
    BinaryOperator<Double> sum1 = Double::sum;
    DoubleBinaryOperator sum2 = Double::sum;
    BinaryOperator<Double> max1 = Double::max;
    DoubleBinaryOperator max2 = Double::max;
    BinaryOperator<Double> min1 = Double::min;
    DoubleBinaryOperator min2 = Double::min;
    Comparator<Double> cmp = Double::compare;

    double[] numbers = { -1, 0, 1, 100, Double.MAX_VALUE, Double.MIN_VALUE };
    for (double i : numbers) {
        for (double j : numbers) {
            assertEquals(i+j, (double) sum1.apply(i, j));
            assertEquals(i+j, sum2.applyAsDouble(i, j));
            assertEquals(Math.max(i,j), (double) max1.apply(i, j));
            assertEquals(Math.max(i,j), max2.applyAsDouble(i, j));
            assertEquals(Math.min(i,j), (double) min1.apply(i, j));
            assertEquals(Math.min(i,j), min2.applyAsDouble(i, j));
            assertEquals(((Double) i).compareTo(j), cmp.compare(i, j));
        }
    }
}
 
源代码4 项目: symbol-sdk-java   文件: Matrix.java
private Matrix join(final Matrix matrix, final boolean isTwoWay,
    final DoubleBinaryOperator op) {
    if (!this.isSameSize(matrix)) {
        throw new IllegalArgumentException("matrix sizes must be equal");
    }

    final Matrix result = this.create(this.getRowCount(), this.getColumnCount());
    this.forEach(
        (r, c, v) -> result
            .setAtUnchecked(r, c, op.applyAsDouble(v, matrix.getAtUnchecked(r, c))));

    if (isTwoWay) {
        matrix.forEach(
            (r, c, v) -> result
                .setAtUnchecked(r, c, op.applyAsDouble(v, this.getAtUnchecked(r, c))));
    }

    return result;
}
 
源代码5 项目: jdk1.8-source-analysis   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code double} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Double, Double>
makeDouble(double identity, DoubleBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble {
        private double state;

        @Override
        public void begin(long size) {
            state = identity;
        }

        @Override
        public void accept(double t) {
            state = operator.applyAsDouble(state, t);
        }

        @Override
        public Double get() {
            return state;
        }

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码6 项目: openjdk-jdk9   文件: ParallelPrefix.java
@Test(dataProvider="doubleSet")
public void testParallelPrefixForDouble(double[] data, int fromIndex, int toIndex, DoubleBinaryOperator op) {
    double[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.applyAsDouble(sequentialResult[index  - 1], sequentialResult[index]);
    }

    double[] parallelResult = data.clone();
    Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op);
    assertArraysEqual(parallelResult, sequentialResult);

    double[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertArraysEqual(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
/** Root task constructor */
public DoubleCumulateTask(DoubleCumulateTask parent,
                          DoubleBinaryOperator function,
                          double[] array, int lo, int hi) {
    super(parent);
    this.function = function; this.array = array;
    this.lo = this.origin = lo; this.hi = this.fence = hi;
    int p;
    this.threshold =
            (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
            <= MIN_PARTITION ? MIN_PARTITION : p;
}
 
/** Subtask constructor */
DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function,
                   double[] array, int origin, int fence, int threshold,
                   int lo, int hi) {
    super(parent);
    this.function = function; this.array = array;
    this.origin = origin; this.fence = fence;
    this.threshold = threshold;
    this.lo = lo; this.hi = hi;
}
 
源代码9 项目: dragonwell8_jdk   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code double} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Double, Double>
makeDouble(double identity, DoubleBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble {
        private double state;

        @Override
        public void begin(long size) {
            state = identity;
        }

        @Override
        public void accept(double t) {
            state = operator.applyAsDouble(state, t);
        }

        @Override
        public Double get() {
            return state;
        }

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码10 项目: dragonwell8_jdk   文件: ArrayPrefixHelpers.java
/** Subtask constructor */
DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function,
                   double[] array, int origin, int fence, int threshold,
                   int lo, int hi) {
    super(parent);
    this.function = function; this.array = array;
    this.origin = origin; this.fence = fence;
    this.threshold = threshold;
    this.lo = lo; this.hi = hi;
}
 
源代码11 项目: Bytecoder   文件: ArrayPrefixHelpers.java
/** Subtask constructor */
DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function,
                   double[] array, int origin, int fence, int threshold,
                   int lo, int hi) {
    super(parent);
    this.function = function; this.array = array;
    this.origin = origin; this.fence = fence;
    this.threshold = threshold;
    this.lo = lo; this.hi = hi;
}
 
源代码12 项目: dragonwell8_jdk   文件: ParallelPrefix.java
@Test(dataProvider="doubleSet")
public void testParallelPrefixForDouble(double[] data, int fromIndex, int toIndex, DoubleBinaryOperator op) {
    double[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.applyAsDouble(sequentialResult[index  - 1], sequentialResult[index]);
    }

    double[] parallelResult = data.clone();
    Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op);
    assertEquals(parallelResult, sequentialResult);

    double[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertEquals(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
源代码13 项目: dragonwell8_jdk   文件: Serial.java
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
源代码14 项目: TencentKona-8   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code double} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Double, Double>
makeDouble(double identity, DoubleBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble {
        private double state;

        @Override
        public void begin(long size) {
            state = identity;
        }

        @Override
        public void accept(double t) {
            state = operator.applyAsDouble(state, t);
        }

        @Override
        public Double get() {
            return state;
        }

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码15 项目: TencentKona-8   文件: ArrayPrefixHelpers.java
/** Subtask constructor */
DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function,
                   double[] array, int origin, int fence, int threshold,
                   int lo, int hi) {
    super(parent);
    this.function = function; this.array = array;
    this.origin = origin; this.fence = fence;
    this.threshold = threshold;
    this.lo = lo; this.hi = hi;
}
 
源代码16 项目: TencentKona-8   文件: ParallelPrefix.java
@DataProvider
public static Object[][] doubleSet(){
    return genericData(size -> IntStream.range(0, size).mapToDouble(i -> (double)i).toArray(),
            new DoubleBinaryOperator[]{
                Double::sum,
                Double::min});
}
 
源代码17 项目: TencentKona-8   文件: Serial.java
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
源代码18 项目: Bytecoder   文件: DoubleAccumulator.java
SerializationProxy(double value,
                   DoubleBinaryOperator function,
                   long identity) {
    this.value = value;
    this.function = function;
    this.identity = identity;
}
 
源代码19 项目: openjdk-jdk9   文件: ArrayPrefixHelpers.java
/** Subtask constructor */
DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function,
                   double[] array, int origin, int fence, int threshold,
                   int lo, int hi) {
    super(parent);
    this.function = function; this.array = array;
    this.origin = origin; this.fence = fence;
    this.threshold = threshold;
    this.lo = lo; this.hi = hi;
}
 
源代码20 项目: Bytecoder   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code double} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Double, Double>
makeDouble(double identity, DoubleBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble {
        private double state;

        @Override
        public void begin(long size) {
            state = identity;
        }

        @Override
        public void accept(double t) {
            state = operator.applyAsDouble(state, t);
        }

        @Override
        public Double get() {
            return state;
        }

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码21 项目: openjdk-jdk9   文件: FloatStamp.java
private static double meetBounds(double a, double b, DoubleBinaryOperator op) {
    if (Double.isNaN(a)) {
        return b;
    } else if (Double.isNaN(b)) {
        return a;
    } else {
        return op.applyAsDouble(a, b);
    }
}
 
源代码22 项目: jdk8u60   文件: ParallelPrefix.java
@Test(dataProvider="doubleSet")
public void testParallelPrefixForDouble(double[] data, int fromIndex, int toIndex, DoubleBinaryOperator op) {
    double[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.applyAsDouble(sequentialResult[index  - 1], sequentialResult[index]);
    }

    double[] parallelResult = data.clone();
    Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op);
    assertEquals(parallelResult, sequentialResult);

    double[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertEquals(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
源代码23 项目: openjdk-jdk8u-backup   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code double} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Double, Double>
makeDouble(double identity, DoubleBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble {
        private double state;

        @Override
        public void begin(long size) {
            state = identity;
        }

        @Override
        public void accept(double t) {
            state = operator.applyAsDouble(state, t);
        }

        @Override
        public Double get() {
            return state;
        }

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码24 项目: Bytecoder   文件: ArrayPrefixHelpers.java
/** Root task constructor */
public DoubleCumulateTask(DoubleCumulateTask parent,
                          DoubleBinaryOperator function,
                          double[] array, int lo, int hi) {
    super(parent);
    this.function = function; this.array = array;
    this.lo = this.origin = lo; this.hi = this.fence = hi;
    int p;
    this.threshold =
        (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
        <= MIN_PARTITION ? MIN_PARTITION : p;
}
 
源代码25 项目: openjdk-jdk9   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code double} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Double, Double>
makeDouble(double identity, DoubleBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble {
        private double state;

        @Override
        public void begin(long size) {
            state = identity;
        }

        @Override
        public void accept(double t) {
            state = operator.applyAsDouble(state, t);
        }

        @Override
        public Double get() {
            return state;
        }

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码26 项目: jdk8u-jdk   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code double} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Double, Double>
makeDouble(double identity, DoubleBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble {
        private double state;

        @Override
        public void begin(long size) {
            state = identity;
        }

        @Override
        public void accept(double t) {
            state = operator.applyAsDouble(state, t);
        }

        @Override
        public Double get() {
            return state;
        }

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码27 项目: openjdk-jdk8u-backup   文件: ArrayPrefixHelpers.java
/** Subtask constructor */
DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function,
                   double[] array, int origin, int fence, int threshold,
                   int lo, int hi) {
    super(parent);
    this.function = function; this.array = array;
    this.origin = origin; this.fence = fence;
    this.threshold = threshold;
    this.lo = lo; this.hi = hi;
}
 
源代码28 项目: JDKSourceCode1.8   文件: ArrayPrefixHelpers.java
/** Subtask constructor */
DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function,
                   double[] array, int origin, int fence, int threshold,
                   int lo, int hi) {
    super(parent);
    this.function = function; this.array = array;
    this.origin = origin; this.fence = fence;
    this.threshold = threshold;
    this.lo = lo; this.hi = hi;
}
 
源代码29 项目: desugar_jdk_libs   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code double} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Double, Double>
makeDouble(double identity, DoubleBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble {
        private double state;

        @Override
        public void begin(long size) {
            state = identity;
        }

        @Override
        public void accept(double t) {
            state = operator.applyAsDouble(state, t);
        }

        @Override
        public Double get() {
            return state;
        }

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码30 项目: openjdk-jdk8u   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code double} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Double, Double>
makeDouble(double identity, DoubleBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble {
        private double state;

        @Override
        public void begin(long size) {
            state = identity;
        }

        @Override
        public void accept(double t) {
            state = operator.applyAsDouble(state, t);
        }

        @Override
        public Double get() {
            return state;
        }

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
 类所在包
 类方法
 同包方法