本文整理了Java中java.util.stream.LongStream.average()
方法的一些代码示例,展示了LongStream.average()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LongStream.average()
方法的具体详情如下:
包路径:java.util.stream.LongStream
类名称:LongStream
方法名:average
[英]Returns an OptionalDouble describing the arithmetic mean of elements of this stream, or an empty optional if this stream is empty. This is a special case of a reduction.
This is a terminal operation.
[中]返回描述此流元素算术平均值的OptionalDouble,如果此流为空,则返回空可选值。这是reduction的一个特例。
这是一个terminal operation。
代码示例来源:origin: prestodb/presto
public Optional<IndexInfo> build()
{
List<Integer> partitions = partitionsSizes.build();
if (partitions.size() == 0) {
return Optional.empty();
}
double avgSize = partitions.stream().mapToLong(Integer::longValue).average().getAsDouble();
double squaredDifferences = partitions.stream().mapToDouble(size -> Math.pow(size - avgSize, 2)).sum();
checkState(partitions.stream().mapToLong(Integer::longValue).sum() == rowsNumber, "Total number of rows in index does not match number of rows in partitions within that index");
return Optional.of(new IndexInfo(rowsNumber, sizeInBytes, squaredDifferences, partitions.size()));
}
}
代码示例来源:origin: prestodb/presto
@VisibleForTesting
static OptionalDouble calculateAverageRowsPerPartition(Collection<PartitionStatistics> statistics)
{
return statistics.stream()
.map(PartitionStatistics::getBasicStatistics)
.map(HiveBasicStatistics::getRowCount)
.filter(OptionalLong::isPresent)
.mapToLong(OptionalLong::getAsLong)
.peek(count -> verify(count >= 0, "count must be greater than or equal to zero"))
.average();
}
代码示例来源:origin: wildfly/wildfly
private static void printStats(Map<String, List<Long>> results) {
for (Map.Entry<String, List<Long>> entry : results.entrySet()) {
System.out.printf("Results for %s%n", entry.getKey());
System.out.printf("Min merge time=%d%n", entry.getValue().stream().min(Long::compare).get());
System.out.printf("Max merge time=%d%n", entry.getValue().stream().max(Long::compare).get());
System.out.printf("Avg merge time=%s%n", entry.getValue().stream().mapToLong(x -> x).average().getAsDouble());
System.out.printf("===================================================================%n");
}
}
}
代码示例来源:origin: apache/hbase
@Override
public OptionalDouble getAvgStoreFileAge() {
return getStoreFileAgeStream().average();
}
代码示例来源:origin: prestodb/presto
double averageIndexSize = indexInfos.stream()
.mapToLong(IndexInfo::getSizeInBytes)
.average()
.getAsDouble();
double squaredDifferencesSizeOfIndex = indexInfos.stream()
代码示例来源:origin: atomix/atomix
@Override
public void run() {
for (int i = 0; i < ITERATIONS; i++) {
try {
iterations.add(runIteration());
} catch (Exception e) {
e.printStackTrace();
return;
}
}
System.out.println("Completed " + ITERATIONS + " iterations");
long averageRunTime = (long) iterations.stream().mapToLong(v -> v).average().getAsDouble();
System.out.println(String.format("averageRunTime: %dms", averageRunTime));
try {
shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: atomix/atomix
@Override
public void run() {
for (int i = 0; i < ITERATIONS; i++) {
try {
iterations.add(runIteration());
} catch (Exception e) {
e.printStackTrace();
return;
}
}
System.out.println("Completed " + ITERATIONS + " iterations");
long averageRunTime = (long) iterations.stream().mapToLong(v -> v).average().getAsDouble();
System.out.println(String.format("averageRunTime: %dms", averageRunTime));
try {
shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: speedment/speedment
default OptionalDouble average(LongPipeline pipeline) {
requireNonNull(pipeline);
return optimize(pipeline).getAsLongStream().average();
}
代码示例来源:origin: prestodb/presto
.filter(WindowOperatorStats::isMeaningful)
.mapToLong(DriverWindowInfo::getNumberOfIndexes)
.average()
.orElse(Double.NaN);
.filter(WindowOperatorStats::isMeaningful)
.mapToLong(DriverWindowInfo::getTotalRowsCount)
.average()
.orElse(Double.NaN);
代码示例来源:origin: prestodb/presto
StageStats stageStats = stageInfo.get().getStageStats();
double avgPositionsPerTask = stageInfo.get().getTasks().stream().mapToLong(task -> task.getStats().getProcessedInputPositions()).average().orElse(Double.NaN);
double squaredDifferences = stageInfo.get().getTasks().stream().mapToDouble(task -> Math.pow(task.getStats().getProcessedInputPositions() - avgPositionsPerTask, 2)).sum();
double sdAmongTasks = Math.sqrt(squaredDifferences / stageInfo.get().getTasks().size());
代码示例来源:origin: DV8FromTheWorld/JDA
/**
* The average time in milliseconds between all shards that discord took to respond to our last heartbeat.
* This roughly represents the WebSocket ping of this session. If there is no shard running this wil return {@code -1}.
*
* <p><b>{@link net.dv8tion.jda.core.requests.RestAction RestAction} request times do not
* correlate to this value!</b>
*
* @return The average time in milliseconds between heartbeat and the heartbeat ack response
*/
default double getAveragePing()
{
return this.getShardCache()
.stream()
.mapToLong(JDA::getPing)
.filter(ping -> ping != -1)
.average()
.orElse(-1D);
}
代码示例来源:origin: gravitee-io/gravitee-gateway
private void report(final EndpointStatus endpointStatus) {
final int previousStatusCode = rule.endpoint().getStatus().code();
final String previousStatusName = rule.endpoint().getStatus().name();
this.endpointStatus.updateStatus(endpointStatus.isSuccess());
endpointStatus.setState(rule.endpoint().getStatus().code());
endpointStatus.setAvailable(!rule.endpoint().getStatus().isDown());
endpointStatus.setResponseTime((long) endpointStatus.getSteps().stream().mapToLong(Step::getResponseTime).average().getAsDouble());
final boolean transition = previousStatusCode != rule.endpoint().getStatus().code();
endpointStatus.setTransition(transition);
if (transition && alertEngineService != null) {
final Event.Builder event = new Event.Builder()
.timestamp(currentTimeMillis())
.context("Gateway", node.id())
.context("Hostname", node.hostname())
.context("Port", port)
.type("HEALTH_CHECK")
.prop("API", rule.api())
.prop("Endpoint name", rule.endpoint().getName())
.prop("Old status", previousStatusName)
.prop("New status", rule.endpoint().getStatus().name())
.prop("Success", endpointStatus.isSuccess());
final Object tenant = node.metadata().get("tenant");
if (tenant != null) {
event.context("Tenant", (String) tenant);
}
alertEngineService.send(event.build());
}
statusHandler.handle(endpointStatus);
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
private static void printStats(Map<String, List<Long>> results) {
for (Map.Entry<String, List<Long>> entry : results.entrySet()) {
System.out.printf("Results for %s%n", entry.getKey());
System.out.printf("Min merge time=%d%n", entry.getValue().stream().min(Long::compare).get());
System.out.printf("Max merge time=%d%n", entry.getValue().stream().max(Long::compare).get());
System.out.printf("Avg merge time=%s%n", entry.getValue().stream().mapToLong(x -> x).average().getAsDouble());
System.out.printf("===================================================================%n");
}
}
}
代码示例来源:origin: io.prestosql/presto-main
public Optional<IndexInfo> build()
{
List<Integer> partitions = partitionsSizes.build();
if (partitions.size() == 0) {
return Optional.empty();
}
double avgSize = partitions.stream().mapToLong(Integer::longValue).average().getAsDouble();
double squaredDifferences = partitions.stream().mapToDouble(size -> Math.pow(size - avgSize, 2)).sum();
checkState(partitions.stream().mapToLong(Integer::longValue).sum() == rowsNumber, "Total number of rows in index does not match number of rows in partitions within that index");
return Optional.of(new IndexInfo(rowsNumber, sizeInBytes, squaredDifferences, partitions.size()));
}
}
代码示例来源:origin: prestosql/presto
public Optional<IndexInfo> build()
{
List<Integer> partitions = partitionsSizes.build();
if (partitions.size() == 0) {
return Optional.empty();
}
double avgSize = partitions.stream().mapToLong(Integer::longValue).average().getAsDouble();
double squaredDifferences = partitions.stream().mapToDouble(size -> Math.pow(size - avgSize, 2)).sum();
checkState(partitions.stream().mapToLong(Integer::longValue).sum() == rowsNumber, "Total number of rows in index does not match number of rows in partitions within that index");
return Optional.of(new IndexInfo(rowsNumber, sizeInBytes, squaredDifferences, partitions.size()));
}
}
代码示例来源:origin: wmr513/reactive
private double calcStdDev() {
mean = durations.stream().mapToLong(d->d).average().orElse(0.0);
double squareDiffSum = 0;
for (long dur : durations) {
squareDiffSum += Math.pow((dur-mean),2);
}
return Math.sqrt((squareDiffSum/(durations.size()-1.0)));
}
代码示例来源:origin: Rsl1122/Plan-PlayerAnalytics
public long toAverageSessionLength() {
OptionalDouble average = sessions.stream().map(Session::getLength)
.mapToLong(i -> i)
.average();
if (average.isPresent()) {
return (long) average.getAsDouble();
}
return 0L;
}
代码示例来源:origin: prestosql/presto
@VisibleForTesting
static OptionalDouble calculateAverageRowsPerPartition(Collection<PartitionStatistics> statistics)
{
return statistics.stream()
.map(PartitionStatistics::getBasicStatistics)
.map(HiveBasicStatistics::getRowCount)
.filter(OptionalLong::isPresent)
.mapToLong(OptionalLong::getAsLong)
.peek(count -> verify(count >= 0, "count must be greater than or equal to zero"))
.average();
}
代码示例来源:origin: one.util/streamex
@Override
public OptionalDouble average() {
if (context.fjp != null)
return context.terminate(stream()::average);
return stream().average();
}
代码示例来源:origin: com.aol.cyclops/cyclops-streams
/**
* Perform an asynchronous average operation
* @see java.util.stream.Stream#mapToLong(ToLongFunction)
* @see java.util.stream.LongStream#average()
* */
default CompletableFuture<OptionalDouble> averageLong(ToLongFunction<? super T> fn){
return CompletableFuture.supplyAsync(()->getStream()
.flatMapToLong(t-> LongStream.of(fn.applyAsLong(t)))
.average(),getExec());
}
/**
内容来源于网络,如有侵权,请联系作者删除!