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


Java DoubleBinaryOperator類代碼示例

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


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

示例1: linearlyMergedUsing

import java.util.function.DoubleBinaryOperator; //導入依賴的package包/類
/**
 * Form a new polynomial by operating on each like term of self and another polynomial.
 * This and the other is not changed.
 *
 * @param operator how to combine each term of this with each term of the `another` polynomial.
 * @param another  the other polynomial involved in the computation.
 * @return the resulting polynomial.
 */
protected Polynomial linearlyMergedUsing(DoubleBinaryOperator operator, /*with*/ Polynomial another) {
    // Validate
    int thisDegree = getDegree();
    int thatDegree = another.getDegree();
    while (another.getCoefficientForExponent(thatDegree) == 0) thatDegree--;
    // Allocate according to the highest degree
    int maxDegree = Math.max(thisDegree, thatDegree);
    double[] resultCoefficientsInNaturalOrder = new double[maxDegree + 1];
    // Apply operator on each term
    for (int exponent = maxDegree, i = 0; exponent >= 0; exponent--, i++) {
        if (exponent <= thisDegree)
            resultCoefficientsInNaturalOrder[i] += getCoefficientForExponent(exponent);
        if (exponent <= thatDegree)
            resultCoefficientsInNaturalOrder[i] = operator.applyAsDouble(
                    resultCoefficientsInNaturalOrder[i],
                    another.getCoefficientForExponent(exponent)
            );
    }
    return new ArrayBasedPoly(resultCoefficientsInNaturalOrder);
}
 
開發者ID:ApolloZhu,項目名稱:APCSAB,代碼行數:29,代碼來源:ArrayBasedPoly.java

示例2: testDoubleMethods

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

示例3: map

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

示例4: map

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

示例5: map

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

示例6: map

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

示例7: map

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

示例8: linearlyMergedUsing

import java.util.function.DoubleBinaryOperator; //導入依賴的package包/類
/**
 * Form a new polynomial by operating on each like term of self and another polynomial.
 * A non-existing term is treated as a term with coefficient of 0.
 * This and the other is not changed.
 *
 * @param operator how to combine each pair of like terms of this and `another` polynomial.
 * @param another  the other polynomial involved in the computation.
 * @return the resulting polynomial.
 * @implSpec Complexity: O(n)
 */
protected Polynomial linearlyMergedUsing(DoubleBinaryOperator operator, /*with*/ Polynomial another) {
    // Validate
    int thisDegree = getDegree();
    int thatDegree = another.getDegree();
    while (another.getCoefficientForExponent(thatDegree) == 0) thatDegree--;
    // Allocate according to the highest degree
    int maxDegree = Math.max(thisDegree, thatDegree);
    TermListNode newHead = null, curTail = null, i = terms,
            /*for efficiency*/ tmp, copy;
    double coefficient;
    // Apply operator on each term
    for (int exponent = maxDegree; exponent >= 0; exponent--) {
        coefficient = 0;
        if (exponent <= thisDegree)
            if ((tmp = getTermForExponent(exponent, i)) != null)
                coefficient = (i = tmp).getCoefficient();
        if (exponent <= thatDegree)
            coefficient = operator.applyAsDouble(coefficient,
                    another.getCoefficientForExponent(exponent));
        if (coefficient == 0) continue; // Skip null
        copy = new TermListNode(exponent, coefficient, null);
        if (newHead == null) newHead = curTail = copy;
        else curTail.setNext(curTail = copy);
    }
    SinglyBasedPolynomial result = new SinglyBasedPolynomial();
    if (newHead != null) result.terms = newHead;
    return result;
}
 
開發者ID:ApolloZhu,項目名稱:APCSAB,代碼行數:39,代碼來源:SinglyBasedPolynomial.java

示例9: makeDouble

import java.util.function.DoubleBinaryOperator; //導入依賴的package包/類
/**
 * 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();
        }
    };
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:43,代碼來源:ReduceOps.java

示例10: DoubleCumulateTask

import java.util.function.DoubleBinaryOperator; //導入依賴的package包/類
/** 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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:13,代碼來源:ArrayPrefixHelpers.java

示例11: super

import java.util.function.DoubleBinaryOperator; //導入依賴的package包/類
MapReduceKeysToDoubleTask
    (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
     MapReduceKeysToDoubleTask<K,V> nextRight,
     ToDoubleFunction<? super K> transformer,
     double basis,
     DoubleBinaryOperator 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

示例12: compute

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

示例13: testDoubleAccumulator

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

示例14: getBinaryOperator

import java.util.function.DoubleBinaryOperator; //導入依賴的package包/類
private static BinaryOperator<Vec3D> getBinaryOperator(DoubleBinaryOperator op) {
  return (a, b) -> {
    double x = op.applyAsDouble(a.x, b.x);
    double y = op.applyAsDouble(a.y, b.y);
    double z = op.applyAsDouble(a.z, b.z);
    return new Vec3D(x, y, z);
  };
}
 
開發者ID:Energyxxer,項目名稱:Vanilla-Injection,代碼行數:9,代碼來源:Vec3D.java

示例15: doubleSet

import java.util.function.DoubleBinaryOperator; //導入依賴的package包/類
@DataProvider
public static Object[][] doubleSet(){
    return genericData(size -> IntStream.range(0, size).mapToDouble(i -> (double)i).toArray(),
            new DoubleBinaryOperator[]{
                Double::sum,
                Double::min});
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:8,代碼來源:ParallelPrefix.java


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