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

x33g5p2x  于2022-01-16 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(1477)

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

Stream.mapToLong介绍

[英]Returns a LongStream consisting of the results of applying the given function to the elements of this stream.

This is an intermediate operation.
[中]返回由将给定函数应用于此流元素的结果组成的LongStream。
这是一个intermediate operation

代码示例

canonical example by Tabnine

public long getDirectorySize(File file) {
 if (!file.exists()) {
  return 0;
 }
 if (file.isFile()) {
  return file.length();
 }
 File[] files;
 if (!file.isDirectory() || (files = file.listFiles()) == null) {
  return 0;
 }
 return Arrays.stream(files).mapToLong(f -> getDirectorySize(f)).sum();
}

代码示例来源:origin: google/guava

/**
 * Returns the sum of all values in this map.
 *
 * <p>This method is not atomic: the sum may or may not include other concurrent operations.
 */
public long sum() {
 return map.values().stream().mapToLong(Long::longValue).sum();
}

代码示例来源:origin: prestodb/presto

public long getPhysicalWrittenDataSize()
{
  return drivers.stream()
      .mapToLong(DriverContext::getPphysicalWrittenDataSize)
      .sum();
}

代码示例来源:origin: SonarSource/sonarqube

private static long[] parsePath(@Nullable String snapshotPath) {
  if (snapshotPath == null) {
   return EMPTY_PATH;
  }
  return PATH_SPLITTER
   .splitToList(snapshotPath)
   .stream()
   .mapToLong(Long::parseLong)
   .toArray();
 }
}

代码示例来源:origin: prestodb/presto

private static String formatNanos(List<Long> list)
  {
    LongSummaryStatistics stats = list.stream().mapToLong(Long::new).summaryStatistics();
    return String.format("Min: %8s  Max: %8s  Avg: %8s  Sum: %8s",
        succinctNanos(stats.getMin() == Long.MAX_VALUE ? 0 : stats.getMin()),
        succinctNanos(stats.getMax() == Long.MIN_VALUE ? 0 : stats.getMax()),
        succinctNanos((long) stats.getAverage()),
        succinctNanos(stats.getSum()));
  }
}

代码示例来源:origin: prestodb/presto

public long getPphysicalWrittenDataSize()
{
  return operatorContexts.stream()
      .mapToLong(OperatorContext::getPhysicalWrittenDataSize)
      .sum();
}

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

public static PrimitiveNodeStream of( Object list )
{
  if ( list == null )
  {
    return empty;
  }
  if ( list instanceof List )
  {
    return new PrimitiveNodeStream( ((List<Node>) list).stream().mapToLong( Node::getId ) );
  }
  else if ( list instanceof Node[] )
  {
    return new PrimitiveNodeStream( Arrays.stream( (Node[]) list ).mapToLong( Node::getId ) );
  }
  throw new IllegalArgumentException( format( "Can not convert to stream: %s", list.getClass().getName() ) );
}

代码示例来源:origin: prestodb/presto

@Override
public long getJoinPositionCount()
{
  return Arrays.stream(lookupSources)
      .mapToLong(LookupSource::getJoinPositionCount)
      .sum();
}

代码示例来源:origin: prestodb/presto

@Override
public long getSizeInBytes()
{
  return INSTANCE_SIZE + channels.stream()
      .flatMap(List::stream)
      .mapToLong(Block::getRetainedSizeInBytes)
      .sum();
}

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

public static PrimitiveRelationshipStream of( Object list )
{
  if ( null == list )
  {
    return empty;
  }
  else if ( list instanceof List )
  {
    return new PrimitiveRelationshipStream(
        ((List<Relationship>) list).stream().mapToLong( Relationship::getId ) );
  }
  else if ( list instanceof Relationship[] )
  {
    return new PrimitiveRelationshipStream(
        Arrays.stream( (Relationship[]) list ).mapToLong( Relationship::getId ) );
  }
  throw new IllegalArgumentException( format( "Can not convert to stream: %s", list.getClass().getName() ) );
}

代码示例来源:origin: prestodb/presto

@Override
public long getInMemorySizeInBytes()
{
  return Arrays.stream(lookupSources).mapToLong(LookupSource::getInMemorySizeInBytes).sum();
}

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

@Override
public long maxCount()
{
  return partitionReaders.stream().mapToLong( LucenePartitionAllDocumentsReader::maxCount ).sum();
}

代码示例来源: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: prestodb/presto

/**
 * Returns the sum of all values in this map.
 *
 * <p>This method is not atomic: the sum may or may not include other concurrent operations.
 */
public long sum() {
 return map.values().stream().mapToLong(Long::longValue).sum();
}

代码示例来源:origin: prestodb/presto

public StripeStatistics(List<ColumnStatistics> columnStatistics)
{
  this.columnStatistics = ImmutableList.copyOf(requireNonNull(columnStatistics, "columnStatistics is null"));
  this.retainedSizeInBytes = INSTANCE_SIZE + columnStatistics.stream().mapToLong(ColumnStatistics::getRetainedSizeInBytes).sum();
}

代码示例来源:origin: prestodb/presto

@VisibleForTesting
public Backoff(int minTries, Duration maxFailureInterval, Ticker ticker, List<Duration> backoffDelayIntervals)
{
  checkArgument(minTries > 0, "minTries must be at least 1");
  requireNonNull(maxFailureInterval, "maxFailureInterval is null");
  requireNonNull(ticker, "ticker is null");
  requireNonNull(backoffDelayIntervals, "backoffDelayIntervals is null");
  checkArgument(!backoffDelayIntervals.isEmpty(), "backoffDelayIntervals must contain at least one entry");
  this.minTries = minTries;
  this.maxFailureIntervalNanos = maxFailureInterval.roundTo(NANOSECONDS);
  this.ticker = ticker;
  this.backoffDelayIntervalsNanos = backoffDelayIntervals.stream()
      .mapToLong(duration -> duration.roundTo(NANOSECONDS))
      .toArray();
}

代码示例来源:origin: prestodb/presto

public long getTotalMemoryReservation()
{
  return stages.values().stream()
      .mapToLong(SqlStageExecution::getTotalMemoryReservation)
      .sum();
}

代码示例来源:origin: prestodb/presto

public void compact()
{
  checkState(!finished, "NestedLoopJoinPagesBuilder is finished");
  pages.stream()
      .forEach(Page::compact);
  estimatedSize = pages.stream()
      .mapToLong(Page::getRetainedSizeInBytes)
      .sum();
}

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

@Override
public long getLastSequenceId() {
  // Return the highest sequence id across all partitions. This will be correct,
  // since there is a single id generator across all partitions for the same producer
  return producers.stream().map(Producer::getLastSequenceId).mapToLong(Long::longValue).max().orElse(-1);
}

代码示例来源:origin: prestodb/presto

public long getUserMemoryReservation()
{
  return stages.values().stream()
      .mapToLong(SqlStageExecution::getUserMemoryReservation)
      .sum();
}

相关文章