Here are the examples of the java api class java.util.function.LongBinaryOperator taken from open source projects.
1. PrimitiveSumMinMaxTest#testLongMethods()
Project: openjdk
File: PrimitiveSumMinMaxTest.java
File: PrimitiveSumMinMaxTest.java
public void testLongMethods() { BinaryOperator<Long> sum1 = Long::sum; LongBinaryOperator sum2 = Long::sum; BinaryOperator<Long> max1 = Long::max; LongBinaryOperator max2 = Long::max; BinaryOperator<Long> min1 = Long::min; LongBinaryOperator min2 = Long::min; Comparator<Long> cmp = Long::compare; long[] numbers = { -1, 0, 1, 100, Long.MAX_VALUE, Long.MIN_VALUE }; for (long i : numbers) { for (long j : numbers) { assertEquals(i + j, (long) sum1.apply(i, j)); assertEquals(i + j, sum2.applyAsLong(i, j)); assertEquals(Math.max(i, j), (long) max1.apply(i, j)); assertEquals(Math.max(i, j), max2.applyAsLong(i, j)); assertEquals(Math.min(i, j), (long) min1.apply(i, j)); assertEquals(Math.min(i, j), min2.applyAsLong(i, j)); assertEquals(((Long) i).compareTo(j), cmp.compare(i, j)); } } }
2. CheckedBinaryOperatorTest#testCheckedLongBinaryOperatorWithCustomHandler()
Project: jOOL
File: CheckedBinaryOperatorTest.java
File: CheckedBinaryOperatorTest.java
@Test public void testCheckedLongBinaryOperatorWithCustomHandler() { final CheckedLongBinaryOperator longBinaryOperator = ( l1, l2) -> { throw new Exception(l1 + ":" + l2); }; final Consumer<Throwable> handler = e -> { throw new IllegalStateException(e); }; LongBinaryOperator test = Unchecked.longBinaryOperator(longBinaryOperator, handler); LongBinaryOperator alias = CheckedLongBinaryOperator.unchecked(longBinaryOperator, handler); assertLongBinaryOperator(test, IllegalStateException.class); assertLongBinaryOperator(alias, IllegalStateException.class); }
3. CheckedBinaryOperatorTest#testCheckedLongBinaryOperator()
Project: jOOL
File: CheckedBinaryOperatorTest.java
File: CheckedBinaryOperatorTest.java
@Test public void testCheckedLongBinaryOperator() { final CheckedLongBinaryOperator longBinaryOperator = ( l1, l2) -> { throw new Exception(l1 + ":" + l2); }; LongBinaryOperator test = Unchecked.longBinaryOperator(longBinaryOperator); LongBinaryOperator alias = CheckedLongBinaryOperator.unchecked(longBinaryOperator); assertLongBinaryOperator(test, UncheckedException.class); assertLongBinaryOperator(alias, UncheckedException.class); }
4. Serial#testLongAccumulator()
Project: openjdk
File: Serial.java
File: Serial.java
static void testLongAccumulator() { LongBinaryOperator plus = (LongBinaryOperatorSerializable & ) ( x, y) -> x + y; LongAccumulator a = new LongAccumulator(plus, -2); a.accumulate(34); LongAccumulator 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.LongAccumulator$SerializationProxy"); }
5. LongAccumulator1#testAccumulate()
Project: java8-tutorial
File: LongAccumulator1.java
File: LongAccumulator1.java
private static void testAccumulate() { LongBinaryOperator op = ( x, y) -> 2 * x + y; LongAccumulator accumulator = new LongAccumulator(op, 1L); ExecutorService executor = Executors.newFixedThreadPool(2); IntStream.range(0, 10).forEach( i -> executor.submit(() -> accumulator.accumulate(i))); ConcurrentUtils.stop(executor); System.out.format("Add: %d\n", accumulator.getThenReset()); }
6. LongStreamExTest#testFoldLeft()
Project: streamex
File: LongStreamExTest.java
File: LongStreamExTest.java
@Test public void testFoldLeft() { // non-associative LongBinaryOperator accumulator = ( x, y) -> (x + y) * (x + y); assertEquals(2322576, LongStreamEx.constant(3, 4).foldLeft(accumulator).orElse(-1)); assertEquals(2322576, LongStreamEx.constant(3, 4).parallel().foldLeft(accumulator).orElse(-1)); assertFalse(LongStreamEx.empty().foldLeft(accumulator).isPresent()); assertEquals(144, LongStreamEx.rangeClosed(1, 3).foldLeft(0L, accumulator)); assertEquals(144, LongStreamEx.rangeClosed(1, 3).parallel().foldLeft(0L, accumulator)); }