Java Code Examples for java.util.LongSummaryStatistics#accept()

The following examples show how to use java.util.LongSummaryStatistics#accept() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LongSummaryStatisticsTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void test_accept() {
    LongSummaryStatistics lss = new LongSummaryStatistics();

    // For long values
    lss.accept(100L);
    assertEquals(1, lss.getCount());
    assertEquals(100L, lss.getSum());
    lss.accept(250L);
    assertEquals(2, lss.getCount());
    assertEquals(350L, lss.getSum());

    // for int values
    lss.accept(50);
    assertEquals(3, lss.getCount());
    assertEquals(400L, lss.getSum());
    lss.accept(200);
    assertEquals(4, lss.getCount());
    assertEquals(600L, lss.getSum());
}
 
Example 2
Source File: TelemetryJmsQoS1IT.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
private static void gatherStatistics(final LongSummaryStatistics stats, final Message message) {
    try {
        final long duration = System.currentTimeMillis() - message.getJMSTimestamp();
        stats.accept(duration);
    } catch (final JMSException e) {
        LOG.error("Failed to get timestamp from message: {}", e.getMessage());
    }
}
 
Example 3
Source File: NatsStatistics.java    From nats.java with Apache License 2.0 5 votes vote down vote up
void registerSummaryStat(LongSummaryStatistics stats, long value) {
    if(!trackAdvanced) {
        return;
    }
    lock.lock();
    try {
        stats.accept(value);
    } finally {
        lock.unlock();
    }
}
 
Example 4
Source File: LongSummaryStatisticsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private static LongSummaryStatistics getLongSummaryStatisticsData1() {
    LongSummaryStatistics lss = new LongSummaryStatistics();
    for (long value : data1) {
        lss.accept(value);
    }
    return lss;
}
 
Example 5
Source File: LongSummaryStatisticsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private static LongSummaryStatistics getLongSummaryStatisticsData2() {
    LongSummaryStatistics lss = new LongSummaryStatistics();
    for (long value : data2) {
        lss.accept(value);
    }
    return lss;
}
 
Example 6
Source File: AverageValueSizeTest.java    From Chronicle-Map with Apache License 2.0 5 votes vote down vote up
public static <V> double averageValueSize(Class<V> valueClass, Iterable<V> values) {
    try (ChronicleMap<Integer, V> testMap = ChronicleMap.of(Integer.class, valueClass)
            // doesn't matter, anyway not a single value will be written to a map
            .averageValueSize(1)
            .entries(1)
            .create()) {
        LongSummaryStatistics statistics = new LongSummaryStatistics();
        for (V value : values) {
            try (MapSegmentContext<Integer, V, ?> c = testMap.segmentContext(0)) {
                statistics.accept(c.wrapValueAsData(value).size());
            }
        }
        return statistics.getAverage();
    }
}