Example usage for java.util.stream Collectors summarizingLong

List of usage examples for java.util.stream Collectors summarizingLong

Introduction

In this page you can find the example usage for java.util.stream Collectors summarizingLong.

Prototype

public static <T> Collector<T, ?, LongSummaryStatistics> summarizingLong(ToLongFunction<? super T> mapper) 

Source Link

Document

Returns a Collector which applies an long -producing mapping function to each input element, and returns summary statistics for the resulting values.

Usage

From source file:Main.java

public static void main(String[] args) {
    LongSummaryStatistics incomeStats = Employee.persons().stream()
            .collect(Collectors.summarizingLong(Employee::getIncome));
    System.out.println(incomeStats);
}

From source file:org.apache.metron.profiler.storm.ProfileBuilderBolt.java

/**
 * Logs information about the {@link TupleWindow}.
 *
 * @param window The tuple window.//  w w w.java  2  s.co m
 */
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());
    }
}

From source file:org.apache.nifi.cluster.coordination.http.replication.ThreadPoolRequestReplicator.java

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");
    }// w ww  .  ja  v a 2s.  co  m

    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());
}