java.util.function.IntBinaryOperator源码实例Demo

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

下面列出了java.util.function.IntBinaryOperator 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk8u   文件: PrimitiveSumMinMaxTest.java
public void testIntMethods() {
    BinaryOperator<Integer> sum1 = Integer::sum;
    IntBinaryOperator sum2 = Integer::sum;
    BinaryOperator<Integer> max1 = Integer::max;
    IntBinaryOperator max2 = Integer::max;
    BinaryOperator<Integer> min1 = Integer::min;
    IntBinaryOperator min2 = Integer::min;
    Comparator<Integer> cmp = Integer::compare;

    int[] numbers = { -1, 0, 1, 100, Integer.MAX_VALUE, Integer.MIN_VALUE };
    for (int i : numbers) {
        for (int j : numbers) {
            assertEquals(i+j, (int) sum1.apply(i, j));
            assertEquals(i+j, sum2.applyAsInt(i, j));
            assertEquals(Math.max(i,j), (int) max1.apply(i, j));
            assertEquals(Math.max(i,j), max2.applyAsInt(i, j));
            assertEquals(Math.min(i,j), (int) min1.apply(i, j));
            assertEquals(Math.min(i,j), min2.applyAsInt(i, j));
            assertEquals(((Integer) i).compareTo(j), cmp.compare(i, j));
        }
    }
}
 
源代码2 项目: dragonwell8_jdk   文件: PrimitiveSumMinMaxTest.java
public void testIntMethods() {
    BinaryOperator<Integer> sum1 = Integer::sum;
    IntBinaryOperator sum2 = Integer::sum;
    BinaryOperator<Integer> max1 = Integer::max;
    IntBinaryOperator max2 = Integer::max;
    BinaryOperator<Integer> min1 = Integer::min;
    IntBinaryOperator min2 = Integer::min;
    Comparator<Integer> cmp = Integer::compare;

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

    int[] numbers = { -1, 0, 1, 100, Integer.MAX_VALUE, Integer.MIN_VALUE };
    for (int i : numbers) {
        for (int j : numbers) {
            assertEquals(i+j, (int) sum1.apply(i, j));
            assertEquals(i+j, sum2.applyAsInt(i, j));
            assertEquals(Math.max(i,j), (int) max1.apply(i, j));
            assertEquals(Math.max(i,j), max2.applyAsInt(i, j));
            assertEquals(Math.min(i,j), (int) min1.apply(i, j));
            assertEquals(Math.min(i,j), min2.applyAsInt(i, j));
            assertEquals(((Integer) i).compareTo(j), cmp.compare(i, j));
        }
    }
}
 
/** Root task constructor */
public IntCumulateTask(IntCumulateTask parent,
                       IntBinaryOperator function,
                       int[] 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 */
IntCumulateTask(IntCumulateTask parent, IntBinaryOperator function,
                int[] 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;
}
 
源代码6 项目: openjdk-jdk8u   文件: ParallelPrefix.java
@DataProvider
public static Object[][] intSet(){
    return genericData(size -> IntStream.range(0, size).toArray(),
            new IntBinaryOperator[]{
                Integer::sum,
                Integer::min});
}
 
源代码7 项目: dragonwell8_jdk   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code int} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Integer, Integer>
makeInt(int identity, IntBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Integer, Integer, ReducingSink>, Sink.OfInt {
        private int state;

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

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

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

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Integer, Integer, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码8 项目: openjdk-jdk8u   文件: ParallelPrefix.java
@Test(dataProvider="intSet")
public void testParallelPrefixForInt(int[] data, int fromIndex, int toIndex, IntBinaryOperator op) {
    int[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.applyAsInt(sequentialResult[index  - 1], sequentialResult[index]);
    }

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

    int[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertEquals(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
源代码9 项目: dragonwell8_jdk   文件: ArrayPrefixHelpers.java
/** Root task constructor */
public IntCumulateTask(IntCumulateTask parent,
                       IntBinaryOperator function,
                       int[] 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;
}
 
源代码10 项目: dragonwell8_jdk   文件: ArrayPrefixHelpers.java
/** Subtask constructor */
IntCumulateTask(IntCumulateTask parent, IntBinaryOperator function,
                int[] 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 项目: openjdk-jdk8u   文件: ArrayPrefixHelpers.java
/** Subtask constructor */
IntCumulateTask(IntCumulateTask parent, IntBinaryOperator function,
                int[] 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
@DataProvider
public static Object[][] intSet(){
    return genericData(size -> IntStream.range(0, size).toArray(),
            new IntBinaryOperator[]{
                Integer::sum,
                Integer::min});
}
 
源代码13 项目: dragonwell8_jdk   文件: ParallelPrefix.java
@Test(dataProvider="intSet")
public void testParallelPrefixForInt(int[] data, int fromIndex, int toIndex, IntBinaryOperator op) {
    int[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.applyAsInt(sequentialResult[index  - 1], sequentialResult[index]);
    }

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

    int[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertEquals(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
源代码14 项目: TencentKona-8   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code int} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Integer, Integer>
makeInt(int identity, IntBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Integer, Integer, ReducingSink>, Sink.OfInt {
        private int state;

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

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

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

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Integer, Integer, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码15 项目: TencentKona-8   文件: ArrayPrefixHelpers.java
/** Subtask constructor */
IntCumulateTask(IntCumulateTask parent, IntBinaryOperator function,
                int[] 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 项目: jdk8u60   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code int} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Integer, Integer>
makeInt(int identity, IntBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Integer, Integer, ReducingSink>, Sink.OfInt {
        private int state;

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

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

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

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

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

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

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

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Integer, Integer, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码18 项目: jdk8u60   文件: ArrayPrefixHelpers.java
/** Root task constructor */
public IntCumulateTask(IntCumulateTask parent,
                       IntBinaryOperator function,
                       int[] 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;
}
 
源代码19 项目: jdk8u60   文件: ArrayPrefixHelpers.java
/** Subtask constructor */
IntCumulateTask(IntCumulateTask parent, IntBinaryOperator function,
                int[] 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 项目: jdk8u60   文件: ParallelPrefix.java
@DataProvider
public static Object[][] intSet(){
    return genericData(size -> IntStream.range(0, size).toArray(),
            new IntBinaryOperator[]{
                Integer::sum,
                Integer::min});
}
 
源代码21 项目: jdk8u60   文件: ParallelPrefix.java
@Test(dataProvider="intSet")
public void testParallelPrefixForInt(int[] data, int fromIndex, int toIndex, IntBinaryOperator op) {
    int[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.applyAsInt(sequentialResult[index  - 1], sequentialResult[index]);
    }

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

    int[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertEquals(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
源代码22 项目: JDKSourceCode1.8   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code int} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Integer, Integer>
makeInt(int identity, IntBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Integer, Integer, ReducingSink>, Sink.OfInt {
        private int state;

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

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

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

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Integer, Integer, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码23 项目: JDKSourceCode1.8   文件: ArrayPrefixHelpers.java
/** Root task constructor */
public IntCumulateTask(IntCumulateTask parent,
                       IntBinaryOperator function,
                       int[] 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;
}
 
源代码24 项目: desugar_jdk_libs   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code int} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Integer, Integer>
makeInt(int identity, IntBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Integer, Integer, ReducingSink>, Sink.OfInt {
        private int state;

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

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

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

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Integer, Integer, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码25 项目: jdk1.8-source-analysis   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code int} values, producing an optional integer result.
 *
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Integer, OptionalInt>
makeInt(IntBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Integer, OptionalInt, ReducingSink>, Sink.OfInt {
        private boolean empty;
        private int state;

        public void begin(long size) {
            empty = true;
            state = 0;
        }

        @Override
        public void accept(int t) {
            if (empty) {
                empty = false;
                state = t;
            }
            else {
                state = operator.applyAsInt(state, t);
            }
        }

        @Override
        public OptionalInt get() {
            return empty ? OptionalInt.empty() : OptionalInt.of(state);
        }

        @Override
        public void combine(ReducingSink other) {
            if (!other.empty)
                accept(other.state);
        }
    }
    return new ReduceOp<Integer, OptionalInt, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码26 项目: jdk1.8-source-analysis   文件: IntPipeline.java
@Override
public final int reduce(int identity, IntBinaryOperator op) {
    return evaluate(ReduceOps.makeInt(identity, op));
}
 
源代码27 项目: jdk1.8-source-analysis   文件: IntPipeline.java
@Override
public final OptionalInt reduce(IntBinaryOperator op) {
    return evaluate(ReduceOps.makeInt(op));
}
 
源代码28 项目: dragonwell8_jdk   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code int} values, producing an optional integer result.
 *
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Integer, OptionalInt>
makeInt(IntBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Integer, OptionalInt, ReducingSink>, Sink.OfInt {
        private boolean empty;
        private int state;

        public void begin(long size) {
            empty = true;
            state = 0;
        }

        @Override
        public void accept(int t) {
            if (empty) {
                empty = false;
                state = t;
            }
            else {
                state = operator.applyAsInt(state, t);
            }
        }

        @Override
        public OptionalInt get() {
            return empty ? OptionalInt.empty() : OptionalInt.of(state);
        }

        @Override
        public void combine(ReducingSink other) {
            if (!other.empty)
                accept(other.state);
        }
    }
    return new ReduceOp<Integer, OptionalInt, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码29 项目: desugar_jdk_libs   文件: IntPipeline.java
@Override
public final OptionalInt reduce(IntBinaryOperator op) {
    return evaluate(ReduceOps.makeInt(op));
}
 
源代码30 项目: dragonwell8_jdk   文件: IntPipeline.java
@Override
public final OptionalInt reduce(IntBinaryOperator op) {
    return evaluate(ReduceOps.makeInt(op));
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法