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