Search in sources :

Example 6 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project eclipse-collections by eclipse.

the class InternalArrayIterate method summarizeLong.

/**
 * @since 8.0
 */
public static <T> LongSummaryStatistics summarizeLong(T[] items, int size, LongFunction<? super T> function) {
    LongSummaryStatistics stats = new LongSummaryStatistics();
    for (int i = 0; i < size; i++) {
        T item = items[i];
        stats.accept(function.longValueOf(item));
    }
    return stats;
}
Also used : LongSummaryStatistics(java.util.LongSummaryStatistics)

Example 7 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project eclipse-collections by eclipse.

the class AbstractRichIterableTestCase method summarizeLong.

@Test
public void summarizeLong() {
    RichIterable<Integer> objects = this.newWith(1, 2, 3);
    LongSummaryStatistics expected = objects.summarizeLong(Integer::longValue);
    Assert.assertEquals(6, expected.getSum());
    Assert.assertEquals(3, expected.getCount());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongSummaryStatistics(java.util.LongSummaryStatistics) Test(org.junit.Test)

Example 8 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project eclipse-collections by eclipse.

the class RichIterable method summarizeLong.

/**
 * Returns the result of summarizing the value returned from applying the LongFunction to
 * each element of the iterable.
 * <p>
 * <pre>
 * LongSummaryStatistics stats =
 *     Lists.mutable.with(1, 2, 3).summarizeLong(Integer::longValue);
 * </pre>
 *
 * @since 8.0
 */
default LongSummaryStatistics summarizeLong(LongFunction<? super T> function) {
    LongSummaryStatistics stats = new LongSummaryStatistics();
    this.each(each -> stats.accept(function.longValueOf(each)));
    return stats;
}
Also used : LongSummaryStatistics(java.util.LongSummaryStatistics)

Example 9 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project eclipse-collections by eclipse.

the class Bag method summarizeLong.

/**
 * @since 8.0
 */
@Override
default LongSummaryStatistics summarizeLong(LongFunction<? super T> function) {
    LongSummaryStatistics stats = new LongSummaryStatistics();
    this.forEachWithOccurrences((each, occurrences) -> {
        long result = function.longValueOf(each);
        for (int i = 0; i < occurrences; i++) {
            stats.accept(result);
        }
    });
    return stats;
}
Also used : LongSummaryStatistics(java.util.LongSummaryStatistics)

Example 10 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project debezium by debezium.

the class Stopwatch method createStatistics.

private static Statistics createStatistics(LongSummaryStatistics stats) {
    boolean some = stats.getCount() > 0L;
    return new Statistics() {

        @Override
        public long getCount() {
            return stats.getCount();
        }

        @Override
        public Duration getMaximum() {
            return some ? Duration.ofNanos(stats.getMax()) : Duration.ZERO;
        }

        @Override
        public Duration getMinimum() {
            return some ? Duration.ofNanos(stats.getMin()) : Duration.ZERO;
        }

        @Override
        public Duration getTotal() {
            return some ? Duration.ofNanos(stats.getSum()) : Duration.ZERO;
        }

        @Override
        public Duration getAverage() {
            return some ? Duration.ofNanos((long) stats.getAverage()) : Duration.ZERO;
        }

        private String fixedLengthSeconds(Duration duration) {
            double seconds = duration.toNanos() * 1e-9;
            String result = new DecimalFormat("##0.00000").format(seconds) + "s";
            if (result.length() == 8)
                return "  " + result;
            if (result.length() == 9)
                return " " + result;
            return result;
        }

        private String fixedLength(long count) {
            String result = new DecimalFormat("###0").format(count);
            if (result.length() == 1)
                return "   " + result;
            if (result.length() == 2)
                return "  " + result;
            if (result.length() == 3)
                return " " + result;
            return result;
        }

        @Override
        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append(fixedLengthSeconds(getTotal()) + " total;");
            sb.append(fixedLength(getCount()) + " samples;");
            sb.append(fixedLengthSeconds(getAverage()) + " avg;");
            sb.append(fixedLengthSeconds(getMinimum()) + " min;");
            sb.append(fixedLengthSeconds(getMaximum()) + " max");
            return sb.toString();
        }
    };
}
Also used : DecimalFormat(java.text.DecimalFormat) Duration(java.time.Duration) LongSummaryStatistics(java.util.LongSummaryStatistics)

Aggregations

LongSummaryStatistics (java.util.LongSummaryStatistics)47 Test (org.junit.Test)18 List (java.util.List)15 Map (java.util.Map)12 CountDownLatch (java.util.concurrent.CountDownLatch)11 ArrayList (java.util.ArrayList)10 Collectors (java.util.stream.Collectors)10 Set (java.util.Set)9 TimeUnit (java.util.concurrent.TimeUnit)9 LoggerFactory (org.slf4j.LoggerFactory)9 HashMap (java.util.HashMap)8 Logger (org.slf4j.Logger)8 BaseTest (io.scalecube.testlib.BaseTest)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Arrays (java.util.Arrays)5 Stream (java.util.stream.Stream)5 Collections (java.util.Collections)4 Comparator (java.util.Comparator)4 Entry (java.util.Map.Entry)4