當前位置: 首頁>>代碼示例>>Java>>正文


Java LongBinaryOperator類代碼示例

本文整理匯總了Java中java.util.function.LongBinaryOperator的典型用法代碼示例。如果您正苦於以下問題:Java LongBinaryOperator類的具體用法?Java LongBinaryOperator怎麽用?Java LongBinaryOperator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LongBinaryOperator類屬於java.util.function包,在下文中一共展示了LongBinaryOperator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testLongMethods

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
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));
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:PrimitiveSumMinMaxTest.java

示例2: map

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
@NonNull
@Override
public MuVector2l map(@NonNull final Vector2l that, @NonNull final LongBinaryOperator operator) {
  this.x = operator.applyAsLong(this.x, that.x());
  this.y = operator.applyAsLong(this.y, that.y());
  return this;
}
 
開發者ID:KyoriPowered,項目名稱:math,代碼行數:8,代碼來源:MuVector2l.java

示例3: map

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
@NonNull
@Override
public MuVector4l map(@NonNull final Vector4l that, @NonNull final LongBinaryOperator operator) {
  this.x = operator.applyAsLong(this.x, that.x());
  this.y = operator.applyAsLong(this.y, that.y());
  this.z = operator.applyAsLong(this.z, that.z());
  this.w = operator.applyAsLong(this.w, that.w());
  return this;
}
 
開發者ID:KyoriPowered,項目名稱:math,代碼行數:10,代碼來源:MuVector4l.java

示例4: map

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
@NonNull
@Override
public MuVector3l map(@NonNull final Vector3l that, @NonNull final LongBinaryOperator operator) {
  this.x = operator.applyAsLong(this.x, that.x());
  this.y = operator.applyAsLong(this.y, that.y());
  this.z = operator.applyAsLong(this.z, that.z());
  return this;
}
 
開發者ID:KyoriPowered,項目名稱:math,代碼行數:9,代碼來源:MuVector3l.java

示例5: getAndAccumulate

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
public final long getAndAccumulate(long x, LongBinaryOperator accumulatorFunction) {
    long prev, next;
    do {
        prev = value;
        next = accumulatorFunction.applyAsLong(prev, x);
    } while (!compareAndSet(prev, next));
    return prev;
}
 
開發者ID:catap,項目名稱:atomic,代碼行數:9,代碼來源:AtomicLong.java

示例6: accumulateAndGet

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
public final long accumulateAndGet(long x, LongBinaryOperator accumulatorFunction) {
    long prev, next;
    do {
        prev = value;
        next = accumulatorFunction.applyAsLong(prev, x);
    } while (!compareAndSet(prev, next));
    return next;
}
 
開發者ID:catap,項目名稱:atomic,代碼行數:9,代碼來源:AtomicLong.java

示例7: getAndAccumulate

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
public final long getAndAccumulate(int i, long x,
                                   LongBinaryOperator accumulatorFunction) {
    long offset = checkedByteOffset(i);
    long prev, next;
    do {
        prev = getRaw(offset);
        next = accumulatorFunction.applyAsLong(prev, x);
    } while (!compareAndSetRaw(offset, prev, next));
    return prev;
}
 
開發者ID:catap,項目名稱:atomic,代碼行數:11,代碼來源:AtomicLongArray.java

示例8: accumulateAndGet

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
public final long accumulateAndGet(int i, long x,
                                   LongBinaryOperator accumulatorFunction) {
    long offset = checkedByteOffset(i);
    long prev, next;
    do {
        prev = getRaw(offset);
        next = accumulatorFunction.applyAsLong(prev, x);
    } while (!compareAndSetRaw(offset, prev, next));
    return next;
}
 
開發者ID:catap,項目名稱:atomic,代碼行數:11,代碼來源:AtomicLongArray.java

示例9: makeLong

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code long} values.
 *
 * @param identity the identity for the combining function
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Long, Long>
makeLong(long identity, LongBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Long, Long, ReducingSink>, Sink.OfLong {
        private long state;

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

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

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

        @Override
        public void combine(ReducingSink other) {
            accept(other.state);
        }
    }
    return new ReduceOp<Long, Long, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:43,代碼來源:ReduceOps.java

示例10: compute

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
public final void compute() {
    final ToLongFunction<? super V> transformer;
    final LongBinaryOperator reducer;
    if ((transformer = this.transformer) != null &&
        (reducer = this.reducer) != null) {
        long r = this.basis;
        for (int i = baseIndex, f, h; batch > 0 &&
                 (h = ((f = baseLimit) + i) >>> 1) > i;) {
            addToPendingCount(1);
            (rights = new MapReduceValuesToLongTask<K,V>
             (this, batch >>>= 1, baseLimit = h, f, tab,
              rights, transformer, r, reducer)).fork();
        }
        for (Node<K,V> p; (p = advance()) != null; )
            r = reducer.applyAsLong(r, transformer.applyAsLong(p.val));
        result = r;
        CountedCompleter<?> c;
        for (c = firstComplete(); c != null; c = c.nextComplete()) {
            @SuppressWarnings("unchecked")
            MapReduceValuesToLongTask<K,V>
                t = (MapReduceValuesToLongTask<K,V>)c,
                s = t.rights;
            while (s != null) {
                t.result = reducer.applyAsLong(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:ConcurrentHashMap.java

示例11: LongCumulateTask

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
/** Root task constructor */
public LongCumulateTask(LongCumulateTask parent,
                        LongBinaryOperator function,
                        long[] 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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:13,代碼來源:ArrayPrefixHelpers.java

示例12: super

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
MapReduceEntriesToLongTask
    (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
     MapReduceEntriesToLongTask<K,V> nextRight,
     ToLongFunction<Map.Entry<K,V>> transformer,
     long basis,
     LongBinaryOperator reducer) {
    super(p, b, i, f, t); this.nextRight = nextRight;
    this.transformer = transformer;
    this.basis = basis; this.reducer = reducer;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:ConcurrentHashMap.java

示例13: super

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
MapReduceKeysToLongTask
    (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
     MapReduceKeysToLongTask<K,V> nextRight,
     ToLongFunction<? super K> transformer,
     long basis,
     LongBinaryOperator reducer) {
    super(p, b, i, f, t); this.nextRight = nextRight;
    this.transformer = transformer;
    this.basis = basis; this.reducer = reducer;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:11,代碼來源:ConcurrentHashMap.java

示例14: testParallelPrefixForLong

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
@Test(dataProvider="longSet")
public void testParallelPrefixForLong(long[] data, int fromIndex, int toIndex, LongBinaryOperator op) {
    long[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.applyAsLong(sequentialResult[index  - 1], sequentialResult[index]);
    }

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

    long[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertArraysEqual(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:ParallelPrefix.java

示例15: longSet

import java.util.function.LongBinaryOperator; //導入依賴的package包/類
@DataProvider(name = "longSet")
public static Object[][] longSet(){
    return genericData(size -> LongStream.range(0, size).toArray(),
            new LongBinaryOperator[]{
                Long::sum,
                Long::min});
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:ParallelPrefix.java


注:本文中的java.util.function.LongBinaryOperator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。