java.util.stream.DoubleStream.allMatch()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中java.util.stream.DoubleStream.allMatch()方法的一些代码示例,展示了DoubleStream.allMatch()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DoubleStream.allMatch()方法的具体详情如下:
包路径:java.util.stream.DoubleStream
类名称:DoubleStream
方法名:allMatch

DoubleStream.allMatch介绍

[英]Returns whether all elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result. If the stream is empty then true is returned and the predicate is not evaluated.

This is a short-circuiting terminal operation.
[中]返回此流的所有元素是否与提供的谓词匹配。如果不需要确定结果,则不能对所有元素的谓词求值。如果流为空,则返回true,并且不计算谓词。
这是一个short-circuiting terminal operation

代码示例

代码示例来源:origin: speedment/speedment

@Override
  public Boolean execute() {
    try (final DoubleStream stream = buildPrevious()) {
      return stream.allMatch(predicate);
    }
  }
}

代码示例来源:origin: speedment/speedment

default boolean allMatch(DoublePipeline pipeline, DoublePredicate predicate) {
  requireNonNull(pipeline);
  requireNonNull(predicate);
  return optimize(pipeline).getAsDoubleStream().allMatch(predicate);
}

代码示例来源:origin: apache/ignite

/**
 * Creates an instance of DiscreteRandomProducer.
 *
 * @param seed Seed.
 * @param probs Discrete distribution probabilities.
 */
public DiscreteRandomProducer(long seed, double... probs) {
  super(seed);
  boolean allElementsAreGEZero = Arrays.stream(probs).allMatch(p -> p >= 0.0);
  boolean sumOfProbsEqOne = Math.abs(Arrays.stream(probs).sum() - 1.0) < EPS;
  A.ensure(allElementsAreGEZero, "all elements should be great or equals 0.0");
  A.ensure(sumOfProbsEqOne, "sum of probs should equal 1.0");
  this.probs = Arrays.copyOf(probs, probs.length);
  this.ids = IntStream.range(0, probs.length).toArray();
  sort(this.probs, ids, 0, probs.length - 1);
  int i = 0;
  int j = probs.length - 1;
  while (i < j) {
    double temp = this.probs[i];
    this.probs[i] = this.probs[j];
    this.probs[j] = temp;
    int idxTmp = this.ids[i];
    this.ids[i] = this.ids[j];
    this.ids[j] = idxTmp;
    i++;
    j--;
  }
  for (i = 1; i < this.probs.length; i++)
    this.probs[i] += this.probs[i - 1];
}

代码示例来源:origin: speedment/speedment

@Override
public boolean allMatch(DoublePredicate predicate) {
  return finallyClose(() -> stream().allMatch(predicate));
}

代码示例来源:origin: net.dongliu/commons-lang

@Override
public boolean allMatch(DoublePredicate predicate) {
  return stream.allMatch(predicate);
}

代码示例来源:origin: com.davidbracewell/mango

@Override
public boolean allMatch(@NonNull SerializableDoublePredicate predicate) {
 return stream.allMatch(predicate);
}

代码示例来源:origin: co.unruly/java-8-matchers

@Override
protected boolean matchesSafely(DoubleStream actual) {
  return actual
      .peek(i -> {nonMatching = i; positionNonMatching++;})
      .allMatch(matcher::matches);
}

代码示例来源:origin: se.ugli.ugli-commons/ugli-commons

@Override
public boolean allMatch(final DoublePredicate predicate) {
  // This is a terminal operation
  return evalAndclose(() -> stream.allMatch(predicate));
}

代码示例来源:origin: com.simiacryptus/mindseye-java

/**
 * Get wieghts double [ ].
 *
 * @return the double [ ]
 */
@Nullable
public double[] getWeights() {
 if (!Arrays.stream(weights).allMatch(v -> Double.isFinite(v))) {
  throw new IllegalStateException(Arrays.toString(weights));
 }
 return weights;
}

代码示例来源:origin: com.simiacryptus/mindseye-java

/**
 * Get bias double [ ].
 *
 * @return the double [ ]
 */
@Nullable
public double[] getBias() {
 if (!Arrays.stream(bias).allMatch(v -> Double.isFinite(v))) {
  throw new IllegalStateException(Arrays.toString(bias));
 }
 return bias;
}

代码示例来源:origin: com.simiacryptus/mindseye

/**
 * Get bias double [ ].
 *
 * @return the double [ ]
 */
@Nullable
public double[] getBias() {
 if (!Arrays.stream(bias).allMatch(v -> Double.isFinite(v))) {
  throw new IllegalStateException(Arrays.toString(bias));
 }
 return bias;
}

代码示例来源:origin: com.simiacryptus/mindseye

/**
 * Get wieghts double [ ].
 *
 * @return the double [ ]
 */
@Nullable
public double[] getWeights() {
 if (!Arrays.stream(weights).allMatch(v -> Double.isFinite(v))) {
  throw new IllegalStateException(Arrays.toString(weights));
 }
 return weights;
}

代码示例来源:origin: com.speedment.runtime/runtime-core

default boolean allMatch(DoublePipeline pipeline, DoublePredicate predicate) {
  requireNonNull(pipeline);
  requireNonNull(predicate);
  return optimize(pipeline).getAsDoubleStream().allMatch(predicate);
}

代码示例来源:origin: com.speedment.runtime/runtime-core

@Override
public boolean allMatch(DoublePredicate predicate) {
  return finallyClose(() -> stream().allMatch(predicate));
}

代码示例来源:origin: com.simiacryptus/mindseye

private static boolean isFinite(@Nonnull final DoubleBufferSet<?, ?> delta) {
 return delta.stream().parallel().flatMapToDouble(y -> Arrays.stream(y.getDelta())).allMatch(d -> Double.isFinite(d));
}

代码示例来源:origin: com.simiacryptus/mindseye

/**
 * Instantiates a new State setByCoord as a copy of the target data buffers in the input setByCoord
 *
 * @param toCopy the to copy
 */
public StateSet(@Nonnull final DeltaSet<K> toCopy) {
 assert toCopy.stream().allMatch(x -> Arrays.stream(x.getDelta()).allMatch(Double::isFinite));
 toCopy.getMap().forEach((layer, layerDelta) -> {
  this.get(layer, layerDelta.target).backup().freeRef();
 });
 assert stream().allMatch(x -> Arrays.stream(x.getDelta()).allMatch(Double::isFinite));
 assert stream().allMatch(x -> x instanceof State);
}

代码示例来源:origin: one.util/streamex

@Override
public boolean allMatch(DoublePredicate predicate) {
  if (context.fjp != null)
    return context.terminate(predicate, stream()::allMatch);
  return stream().allMatch(predicate);
}

代码示例来源:origin: OpenGamma/Strata

@ImmutableValidator
private void validate() {
 if (pair.getBase().equals(pair.getCounter()) && !rates.stream().allMatch(v -> v == 1d)) {
  throw new IllegalArgumentException("Conversion rate between identical currencies must be one");
 }
}

代码示例来源:origin: ICOnator/ICOnator-backend

@Test
public void test2() {
  double[] data = new double[]{500, 501, 498, 500, 500, 500, 500, 500, 500, 501, 501, 498, 510};
  OutlierCalculation oc = new OutlierCalculation(data, 1.0, 1.0);
  LOG.info("LowerBound Threshold: " + oc.getLowerBoundThreshold());
  LOG.info("UpperBound Threshold: " + oc.getUpperBoundThreshold());
  LOG.info("LowerBound Outliers: " + Arrays.toString(oc.findLowerBoundOutlierValues()));
  LOG.info("UpperBound Outliers: " + Arrays.toString(oc.findUpperBoundOutlierValues()));
  assertTrue(oc.findUpperBoundOutlierValues().length == 1);
  assertTrue(oc.findLowerBoundOutlierValues().length == 0);
  assertTrue(Arrays.stream(oc.findUpperBoundOutlierValues()).allMatch((value) -> value == 510.0));
}

代码示例来源:origin: ICOnator/ICOnator-backend

@Test
public void test1() {
  double[] data = new double[]{500, 501, 498, 500, 500, 510};
  OutlierCalculation oc = new OutlierCalculation(data, 1.0, 1.0);
  LOG.info("LowerBound Threshold: " + oc.getLowerBoundThreshold());
  LOG.info("UpperBound Threshold: " + oc.getUpperBoundThreshold());
  LOG.info("LowerBound Outliers: " + Arrays.toString(oc.findLowerBoundOutlierValues()));
  LOG.info("UpperBound Outliers: " + Arrays.toString(oc.findUpperBoundOutlierValues()));
  assertTrue(oc.findUpperBoundOutlierValues().length == 1);
  assertTrue(oc.findLowerBoundOutlierValues().length == 0);
  assertTrue(Arrays.stream(oc.findUpperBoundOutlierValues()).allMatch((value) -> value == 510.0));
}

相关文章