当前位置: 首页>>代码示例>>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;未经允许,请勿转载。