本文整理了Java中java.util.stream.DoubleStream.min()
方法的一些代码示例,展示了DoubleStream.min()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DoubleStream.min()
方法的具体详情如下:
包路径:java.util.stream.DoubleStream
类名称:DoubleStream
方法名:min
[英]Returns an OptionalDouble describing the minimum element of this stream, or an empty OptionalDouble if this stream is empty. The minimum element will be Double.NaN if any stream element was NaN. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. This is a special case of a reduction and is equivalent to:
return reduce(Double::min);
This is a terminal operation.
[中]返回描述此流的最小元素的OptionalDouble,如果此流为空,则返回空OptionalDouble。最小元素将是双倍的。如果任何流元素为NaN,则为NaN。与数值比较运算符不同,该方法认为负零严格小于正零。这是reduction的一个特例,相当于:
return reduce(Double::min);
这是一个terminal operation。
代码示例来源:origin: thinkaurelius/titan
private double min(double... numbers) {
return Arrays.stream(numbers).min().getAsDouble();
}
代码示例来源:origin: prestodb/presto
public static double min(double... values)
{
return DoubleStream.of(values)
.min()
.getAsDouble();
}
代码示例来源:origin: JanusGraph/janusgraph
private double min(double... numbers) {
return Arrays.stream(numbers).min().getAsDouble();
}
代码示例来源:origin: decaywood/XueQiuSuperSpider
public static double min(double... nums) {
if(nums.length == 0) return Double.MIN_VALUE;
return Arrays.stream(nums).min().getAsDouble();
}
代码示例来源:origin: speedment/speedment
@Override
public OptionalDouble execute() {
try (final DoubleStream stream = buildPrevious()) {
return stream.min();
}
}
}
代码示例来源:origin: OryxProject/oryx
private double minInterClusterDissimilarityForPoint(
int otherClusterID,
double[] point,
Map<Integer, Iterable<double[]>> clusteredPointsMap) {
return clusteredPointsMap.entrySet().stream().mapToDouble(entry -> {
// only compute dissimilarities with other clusters
if (entry.getKey().equals(otherClusterID)) {
return Double.POSITIVE_INFINITY;
}
return clusterDissimilarityForPoint(point, iterableToList(entry.getValue()), false);
}).min().orElse(Double.POSITIVE_INFINITY);
}
代码示例来源:origin: speedment/speedment
default OptionalDouble min(DoublePipeline pipeline) {
requireNonNull(pipeline);
return optimize(pipeline).getAsDoubleStream().min();
}
代码示例来源:origin: apache/storm
double min = load == null ? 0 : targetsInScope.stream().mapToDouble((key) -> load.get(key)).min().getAsDouble();
for (int target : targetsInScope) {
IndexAndWeights val = orig.get(target);
代码示例来源:origin: prestodb/presto
private SymbolStatsEstimate buildSymbolStatistics(List<Object> values, Session session, Type type)
{
List<Object> nonNullValues = values.stream()
.filter(Objects::nonNull)
.collect(toImmutableList());
if (nonNullValues.isEmpty()) {
return SymbolStatsEstimate.zero();
}
double[] valuesAsDoubles = nonNullValues.stream()
.map(value -> toStatsRepresentation(metadata, session, type, value))
.filter(OptionalDouble::isPresent)
.mapToDouble(OptionalDouble::getAsDouble)
.toArray();
double lowValue = DoubleStream.of(valuesAsDoubles).min().orElse(Double.NEGATIVE_INFINITY);
double highValue = DoubleStream.of(valuesAsDoubles).max().orElse(Double.POSITIVE_INFINITY);
double valuesCount = values.size();
double nonNullValuesCount = nonNullValues.size();
long distinctValuesCount = nonNullValues.stream().distinct().count();
return SymbolStatsEstimate.builder()
.setNullsFraction((valuesCount - nonNullValuesCount) / valuesCount)
.setLowValue(lowValue)
.setHighValue(highValue)
.setDistinctValuesCount(distinctValuesCount)
.build();
}
}
代码示例来源:origin: google/guava
public void testEquivalentStreams() {
// For datasets of many double values created from an array, we test many combinations of finite
// and non-finite values:
for (ManyValues values : ALL_MANY_VALUES) {
double[] array = values.asArray();
Stats stats = Stats.of(array);
// instance methods on Stats vs on instance methods on DoubleStream
assertThat(stats.count()).isEqualTo(stream(array).count());
assertEquivalent(stats.mean(), stream(array).average().getAsDouble());
assertEquivalent(stats.sum(), stream(array).sum());
assertEquivalent(stats.max(), stream(array).max().getAsDouble());
assertEquivalent(stats.min(), stream(array).min().getAsDouble());
// static method on Stats vs on instance method on DoubleStream
assertEquivalent(Stats.meanOf(array), stream(array).average().getAsDouble());
// instance methods on Stats vs instance methods on DoubleSummaryStatistics
DoubleSummaryStatistics streamStats = stream(array).summaryStatistics();
assertThat(stats.count()).isEqualTo(streamStats.getCount());
assertEquivalent(stats.mean(), streamStats.getAverage());
assertEquivalent(stats.sum(), streamStats.getSum());
assertEquivalent(stats.max(), streamStats.getMax());
assertEquivalent(stats.min(), streamStats.getMin());
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Find the minimum value in a window of values
* If all values are missing/null/NaN, the return value will be NaN
*/
public static double min(double[] values) {
return Arrays.stream(values).min().orElse(Double.NaN);
}
代码示例来源:origin: com.github.wshackle/poseList3DPlot
/**
* Map all elements of a stream to a double and get the min.
*
* @param <T> Type of Stream which must match type of mapper
* @param stream the value of stream
* @param mapper the value of mapper
* @return the double
*/
public static <T> double minStream(Stream<T> stream, ToDoubleFunction<T> mapper) {
return stream.mapToDouble(mapper).min().orElse(Double.POSITIVE_INFINITY);
}
代码示例来源:origin: io.prestosql/presto-main
public static double min(double... values)
{
return DoubleStream.of(values)
.min()
.getAsDouble();
}
代码示例来源:origin: com.simiacryptus/mindseye
/**
* Min double.
*
* @param history the history
* @return the double
*/
public double min(@Nonnull List<StepRecord> history) {
return history.stream().mapToDouble(x -> x.fitness).min().orElse(Double.NaN);
}
代码示例来源:origin: io.committed.krill/krill
/**
* Gets the min X.
*
* @return the min X
*/
private double getMinX() {
return lines.values().stream().mapToDouble(l -> l.getPosition().getMinX()).min()
.getAsDouble();
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch
/**
* Find the minimum value in a window of values
* If all values are missing/null/NaN, the return value will be NaN
*/
public static double min(double[] values) {
return Arrays.stream(values).min().orElse(Double.NaN);
}
代码示例来源:origin: com.simiacryptus/mindseye-labs
/**
* Min double.
*
* @param history the history
* @return the double
*/
public double min(@Nonnull List<StepRecord> history) {
return history.stream().mapToDouble(x -> x.fitness).min().orElse(Double.NaN);
}
代码示例来源:origin: cheng-li/pyramid
public static double normalizedRMSE(double[] labels, double[] predictions){
double rmse =rmse(labels, predictions);
double max = Arrays.stream(labels).max().getAsDouble();
double min = Arrays.stream(labels).min().getAsDouble();
return rmse/(max-min);
}
}
代码示例来源:origin: com.wavefront/java-lib
public double min() {
// This is a lie if the winning centroid's weight > 1
return perThreadHistogramBins.values().stream().flatMap(List::stream).map(b -> b.dist.centroids()).
mapToDouble(cs -> getFirst(cs, new Centroid(MAX_VALUE)).mean()).min().orElse(NaN);
}
代码示例来源:origin: pravega/pravega
private void outputStats(String indexName, String statsName, Function<PerfResult, Long> statsProvider, Collection<PerfResult> results) {
double min = results.stream().mapToDouble(r -> statsProvider.apply(r) / (double) r.count).min().orElse(-1) / NANOS_TO_MILLIS;
double max = results.stream().mapToDouble(r -> statsProvider.apply(r) / (double) r.count).max().orElse(-1) / NANOS_TO_MILLIS;
double avg = results.stream().mapToDouble(r -> statsProvider.apply(r) / (double) r.count).average().orElse(-1) / NANOS_TO_MILLIS;
System.out.println(String.format("%s.%s: Min = %.2f us, Max = %.2f us, Avg = %.2f us", indexName, statsName, min, max, avg));
}
内容来源于网络,如有侵权,请联系作者删除!