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

x33g5p2x  于2022-01-17 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(451)

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

Collectors.summarizingLong介绍

暂无

代码示例

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

@Override
public long getSize() {
  return getEventFilesFromDisk()
    .collect(Collectors.summarizingLong(file -> file.length()))
    .getSum();
}

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

private void logTimingInfo(final AsyncClusterResponse response) {
  // Calculate min, max, mean for the requests
  final LongSummaryStatistics stats = response.getNodesInvolved().stream()
      .map(p -> response.getNodeResponse(p).getRequestDuration(TimeUnit.MILLISECONDS))
      .collect(Collectors.summarizingLong(Long::longValue));
  final StringBuilder sb = new StringBuilder();
  sb.append("Node Responses for ").append(response.getMethod()).append(" ").append(response.getURIPath()).append(" (Request ID ").append(response.getRequestIdentifier()).append("):\n");
  for (final NodeIdentifier node : response.getNodesInvolved()) {
    sb.append(node).append(": ").append(response.getNodeResponse(node).getRequestDuration(TimeUnit.MILLISECONDS)).append(" millis\n");
  }
  logger.debug("For {} {} (Request ID {}), minimum response time = {}, max = {}, average = {} ms",
      response.getMethod(), response.getURIPath(), response.getRequestIdentifier(), stats.getMin(), stats.getMax(), stats.getAverage());
  logger.debug(sb.toString());
}

代码示例来源:origin: aol/cyclops

default LongSummaryStatistics longStats(ToLongFunction<T> fn){
  return stream().collect(Collectors.summarizingLong(fn));
}
default IntSummaryStatistics intStats(ToIntFunction<T> fn){

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

/**
 * Logs information about the {@link TupleWindow}.
 *
 * @param window The tuple window.
 */
private void log(TupleWindow window) {
 // summarize the newly received tuples
 LongSummaryStatistics received = window.get()
     .stream()
     .map(tuple -> getField(TIMESTAMP_TUPLE_FIELD, tuple, Long.class))
     .collect(Collectors.summarizingLong(Long::longValue));
 LOG.debug("Tuple(s) received; count={}, min={}, max={}, range={} ms",
     received.getCount(),
     received.getMin(),
     received.getMax(),
     received.getMax() - received.getMin());
 if (window.getExpired().size() > 0) {
  // summarize the expired tuples
  LongSummaryStatistics expired = window.getExpired()
      .stream()
      .map(tuple -> getField(TIMESTAMP_TUPLE_FIELD, tuple, Long.class))
      .collect(Collectors.summarizingLong(Long::longValue));
  LOG.debug("Tuple(s) expired; count={}, min={}, max={}, range={} ms, lag={} ms",
      expired.getCount(),
      expired.getMin(),
      expired.getMax(),
      expired.getMax() - expired.getMin(),
      received.getMin() - expired.getMin());
 }
}

代码示例来源:origin: apssouza22/java-microservice

public LongSummaryStatistics getStatistics() {
    return this.events.stream().
        collect(Collectors.summarizingLong(TodoChangedEvent::getPriority));
  }
}

代码示例来源:origin: apssouza22/java-microservice

public LongSummaryStatistics getStatistics() {
    return this.events.stream().
        collect(Collectors.summarizingLong(TodoServiceMethodInvokedEvent::getDuration));
  }
}

代码示例来源:origin: sing-group/GC4S

protected String getLongColumnSummary(TableModel model, int columnModel) {
  List<Long> values = new LinkedList<>();
  for (int row = 0; row < model.getRowCount(); row++) {
    values.add((Long) model.getValueAt(row, columnModel));
  }
  LongSummaryStatistics statistics = values.stream()
    .collect(Collectors.summarizingLong(Long::longValue));
  return getSummary("integer", new SummaryStatistics(statistics));
}

代码示例来源:origin: hazelcast/hazelcast-jet-code-samples

public static void main(String[] args) throws Exception {
  // Warmup
  measure();
  measure();
  measure();
  List<Long> timings = new ArrayList<>();
  for (int i = 0; i < 9; i++) {
    timings.add(measure());
    System.gc();
  }
  System.out.println(timings.stream().collect(summarizingLong(x -> x)));
}

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

/**
* Verify if startStreamCut comes before endStreamCut.
*/
private void verifyStartAndEndStreamCuts(final StreamCut startStreamCut, final StreamCut endStreamCut) {
  final Map<Segment, Long> startPositions = startStreamCut.asImpl().getPositions();
  final Map<Segment, Long> endPositions = endStreamCut.asImpl().getPositions();
  //check offsets for overlapping segments.
  startPositions.keySet().stream().filter(endPositions::containsKey)
        .forEach(s -> Preconditions.checkArgument(startPositions.get(s) <= endPositions.get(s),
            "Segment offset in startStreamCut should be <= segment offset in endStreamCut."));
  val fromSCSummary = startPositions.keySet()
                   .stream().collect(summarizingLong(Segment::getSegmentId));
  val toSCSummary = endPositions.keySet()
                 .stream().collect(summarizingLong(Segment::getSegmentId));
  Preconditions.checkArgument(fromSCSummary.getMin() <= toSCSummary.getMin(),
      "Start stream cut must precede end stream cut.");
  Preconditions.checkArgument(fromSCSummary.getMax() <= toSCSummary.getMax(),
      "Start stream cut must precede end stream cut.");
}

代码示例来源:origin: com.oath.cyclops/cyclops

default LongSummaryStatistics longStats(ToLongFunction<T> fn){
  return stream().collect(Collectors.summarizingLong(fn));
}
default IntSummaryStatistics intStats(ToIntFunction<T> fn){

代码示例来源:origin: zalando-incubator/catwatch

.flatMap(Set::stream)
.collect(groupingBy(Map.Entry::getKey,
    summarizingLong(entry -> ((Number) ((Map.Entry) entry).getValue()).longValue())));

代码示例来源:origin: hazelcast/hazelcast-jet-code-samples

private void go() throws Exception {
  List<Long> timings = new ArrayList<>();
  try {
    setup();
    // Warmup
    measure();
    measure();
    measure();
    for (int i = 0; i < 9; i++) {
      timings.add(measure());
      System.gc();
    }
  } finally {
    Jet.shutdownAll();
  }
  System.out.println(timings.stream().collect(summarizingLong(x -> x)));
}

代码示例来源:origin: xiancloud/xian

LongSummaryStatistics intSummaryStatistics = consumeTimes.stream().collect(Collectors.summarizingLong(value -> value));

代码示例来源:origin: xiancloud/xian

LongSummaryStatistics intSummaryStatistics = consumeTimes.stream().collect(Collectors.summarizingLong(value -> value));

代码示例来源:origin: Netflix/spectator

@Test
public void distributionSummaries() {
 Registry r = newRegistry(true, 10000);
 r.distributionSummary("foo").record(1L);
 r.distributionSummary("foo", "a", "1", "b", "2").record(1L);
 r.distributionSummary("foo", "a", "1", "b", "3").record(13L);
 r.distributionSummary("foo", "a", "1", "b", "2").record(1L);
 r.distributionSummary("bar", "a", "1", "b", "2").record(1L);
 Assertions.assertEquals(4, r.distributionSummaries().count());
 final LongSummaryStatistics countSummary = r.distributionSummaries()
   .filter(Functions.nameEquals("foo"))
   .collect(Collectors.summarizingLong(DistributionSummary::count));
 Assertions.assertEquals(3L, countSummary.getCount());
 Assertions.assertEquals(4L, countSummary.getSum());
 Assertions.assertEquals(2L, countSummary.getMax());
 final LongSummaryStatistics totalSummary = r.distributionSummaries()
   .filter(Functions.nameEquals("foo"))
   .collect(Collectors.summarizingLong(DistributionSummary::totalAmount));
 Assertions.assertEquals(3L, totalSummary.getCount());
 Assertions.assertEquals(16L, totalSummary.getSum());
 Assertions.assertEquals(13L, totalSummary.getMax());
}

代码示例来源:origin: Netflix/spectator

@Test
public void timers() {
 Registry r = newRegistry(true, 10000);
 r.timer("foo").record(1L, TimeUnit.NANOSECONDS);
 r.timer("foo", "a", "1", "b", "2").record(1L, TimeUnit.NANOSECONDS);
 r.timer("foo", "a", "1", "b", "3").record(13L, TimeUnit.NANOSECONDS);
 r.timer("foo", "a", "1", "b", "2").record(1L, TimeUnit.NANOSECONDS);
 r.timer("bar", "a", "1", "b", "2").record(1L, TimeUnit.NANOSECONDS);
 Assertions.assertEquals(4, r.timers().count());
 final LongSummaryStatistics countSummary = r.timers()
   .filter(Functions.nameEquals("foo"))
   .collect(Collectors.summarizingLong(Timer::count));
 Assertions.assertEquals(3L, countSummary.getCount());
 Assertions.assertEquals(4L, countSummary.getSum());
 Assertions.assertEquals(2L, countSummary.getMax());
 final LongSummaryStatistics totalSummary = r.timers()
   .filter(Functions.nameEquals("foo"))
   .collect(Collectors.summarizingLong(Timer::totalTime));
 Assertions.assertEquals(3L, totalSummary.getCount());
 Assertions.assertEquals(16L, totalSummary.getSum());
 Assertions.assertEquals(13L, totalSummary.getMax());
}

代码示例来源:origin: Netflix/spectator

@Test
public void counters() {
 Registry r = newRegistry(true, 10000);
 r.counter("foo").increment();
 r.counter("foo", "a", "1", "b", "2").increment();
 r.counter("foo", "a", "1", "b", "3").increment(13L);
 r.counter("foo", "a", "1", "b", "2").increment();
 r.counter("bar", "a", "1", "b", "2").increment();
 Assertions.assertEquals(4, r.counters().count());
 final LongSummaryStatistics summary = r.counters()
   .filter(Functions.nameEquals("foo"))
   .collect(Collectors.summarizingLong(Counter::count));
 Assertions.assertEquals(3L, summary.getCount());
 Assertions.assertEquals(16L, summary.getSum());
 Assertions.assertEquals(13L, summary.getMax());
}

相关文章