本文整理汇总了Java中java.util.LongSummaryStatistics类的典型用法代码示例。如果您正苦于以下问题:Java LongSummaryStatistics类的具体用法?Java LongSummaryStatistics怎么用?Java LongSummaryStatistics使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LongSummaryStatistics类属于java.util包,在下文中一共展示了LongSummaryStatistics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ensureSidesAddUp
import java.util.LongSummaryStatistics; //导入依赖的package包/类
public static void ensureSidesAddUp(Map<GroupedSearchResultRow, Long> result) {
Map<String, LongSummaryStatistics> sideTotals =
result
.entrySet()
.stream()
.collect(
Collectors.groupingBy(
e -> e.getKey().getFieldName(),
Collectors.summarizingLong(e -> e.getValue().longValue())));
int numDistinctValues =
sideTotals
.values()
.stream()
.map(LongSummaryStatistics::getSum)
.distinct()
.collect(Collectors.toList())
.size();
if (numDistinctValues != 1) {
log.error("Sides do not add up");
sideTotals.entrySet().forEach(e -> log.info("{}: {}", e.getKey(), e.getValue().getSum()));
}
assertEquals(1, numDistinctValues);
}
示例2: recommendations
import java.util.LongSummaryStatistics; //导入依赖的package包/类
@Override
public String recommendations() {
List<Metric> metrics = data.entrySet().stream()
.map(entry -> entry.getValue().entrySet().stream()
.map(data -> new Metric(entry.getKey(), data.getKey(), data.getValue()))
.collect(Collectors.toList()))
.collect(ArrayList::new, List::addAll, List::addAll);
Map<String, List<Metric>> runaways = new HashMap<>();
metrics.stream().collect(Collectors.groupingBy(Metric::name)).entrySet().forEach(entry -> {
LongSummaryStatistics statistics = entry.getValue().stream()
.collect(Collectors.summarizingLong(Metric::value));
runaways.put(entry.getKey(),
entry.getValue().stream().filter(metric -> metric.value() <= statistics.getAverage())
.sorted((m1, m2) -> (int) (m1.value() - m2.value())).collect(Collectors.toList()));
});
return this.buildRunaways(runaways);
}
示例3: testLongStatistics
import java.util.LongSummaryStatistics; //导入依赖的package包/类
public void testLongStatistics() {
List<LongSummaryStatistics> instances = new ArrayList<>();
instances.add(countTo(1000).stream().collect(Collectors.summarizingLong(i -> i)));
instances.add(countTo(1000).stream().mapToLong(i -> i).summaryStatistics());
instances.add(countTo(1000).stream().mapToLong(i -> i).collect(LongSummaryStatistics::new,
LongSummaryStatistics::accept,
LongSummaryStatistics::combine));
instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingLong(i -> i)));
instances.add(countTo(1000).parallelStream().mapToLong(i -> i).summaryStatistics());
instances.add(countTo(1000).parallelStream().mapToLong(i -> i).collect(LongSummaryStatistics::new,
LongSummaryStatistics::accept,
LongSummaryStatistics::combine));
for (LongSummaryStatistics stats : instances) {
assertEquals(stats.getCount(), 1000);
assertEquals(stats.getSum(), (long) countTo(1000).stream().mapToInt(i -> i).sum());
assertEquals(stats.getAverage(), (double) stats.getSum() / stats.getCount());
assertEquals(stats.getMax(), 1000L);
assertEquals(stats.getMin(), 1L);
}
}
示例4: main
import java.util.LongSummaryStatistics; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.setProperty("bootstrap.servers", args[0]);
props.setProperty("group.id", UUID.randomUUID().toString());
props.setProperty("key.deserializer", LongDeserializer.class.getName());
props.setProperty("value.deserializer", TradeDeserializer.class.getName());
props.setProperty("auto.offset.reset", "earliest");
KafkaConsumer<Long, Trade> consumer = new KafkaConsumer<>(props);
List<String> topics = Arrays.asList(args[1]);
consumer.subscribe(topics);
System.out.println("Subscribed to topics " + topics);
long count = 0;
long start = System.nanoTime();
while (true) {
ConsumerRecords<Long, Trade> poll = consumer.poll(5000);
System.out.println("Partitions in batch: " + poll.partitions());
LongSummaryStatistics stats = StreamSupport.stream(poll.spliterator(), false)
.mapToLong(r -> r.value().getTime()).summaryStatistics();
System.out.println("Oldest record time: " + stats.getMin() + ", newest record: " + stats.getMax());
count += poll.count();
long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
long rate = (long) ((double) count / elapsed * 1000);
System.out.printf("Total count: %,d in %,dms. Average rate: %,d records/s %n", count, elapsed, rate);
}
}
示例5: minMaxDiff
import java.util.LongSummaryStatistics; //导入依赖的package包/类
public static long minMaxDiff(String path) throws IOException {
LongSummaryStatistics stats = Files.list(Paths.get(path))
.flatMap(f -> uncheckCall(() -> Files.lines(f)))
.mapToLong(l -> {
try {
String ts = l.split(",")[3];
if (ts.length() != 13) {
throw new IllegalArgumentException();
}
return Long.valueOf(ts);
} catch (Exception ignored) {
System.out.println("Malformed line: " + l);
return Long.MIN_VALUE;
}
}).filter(l -> l > Long.MIN_VALUE)
.summaryStatistics();
return stats.getMax() - stats.getMin();
}
示例6: main
import java.util.LongSummaryStatistics; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
List<Salary> list = SalaryFileUtils.readFromFile();
long start = System.currentTimeMillis();
HashBiMap<String, LongSummaryStatistics> groupMap = list.parallelStream()
.filter(s -> s.getTotalIncome() > 100000)
.collect(
Collectors.groupingBy(
Salary::namePrefix,
() -> HashBiMap.create(),
Collectors.summarizingLong(Salary::getTotalIncome)
)
);
groupMap.values()
.parallelStream()
.sorted(Comparator.comparingLong(LongSummaryStatistics::getSum).reversed()) // 默认是从小到大排序
.limit(10)
.forEachOrdered(ls -> {
System.out.format("[%s], count: %s, sum: %s \n",
groupMap.inverse().get(ls), ls.getCount(), ls.getSum());
});
System.out.println("elapsed time : " + (System.currentTimeMillis() - start));
}
示例7: getSummary
import java.util.LongSummaryStatistics; //导入依赖的package包/类
@Override
public String getSummary() {
StringBuilder retval = new StringBuilder("PZXPilotBlock:\n");
LongSummaryStatistics stats =
pulses.getPulseLengths()
.subList(0, pulses.getPulseLengths().size() - 2)
.stream().mapToLong(x -> x).summaryStatistics();
retval.append("Average pilot pulse:").append(Math.round(stats.getAverage())).append(" tstates, ")
.append(String.format("%.2f", stats.getAverage()/ PILOT_LENGTH*100.0)).append("% of expected\n");
retval.append("Sync1 pulse:").append(sync1Length).append(" tstates, ")
.append(String.format("%.2f", (double)sync1Length/SYNC1*100.0)).append("% of expected\n");
retval.append("Sync2 pulse:").append(sync2Length).append(" tstates, ")
.append(String.format("%.2f", (double)sync2Length/SYNC2*100.0)).append("% of expected\n");
retval.append(pulses.toString());
return retval.toString();
}
示例8: getSummaryText
import java.util.LongSummaryStatistics; //导入依赖的package包/类
/**
*
* @param type the value of type
* @param standardPulse the value of standardPulse
* @param stats the value of stats
* @return the String
*/
private String getSummaryText(String type, int standardPulse, LongSummaryStatistics stats) {
StringBuilder retval = new StringBuilder();
long low = stats.getMin();
long high = stats.getMax();
double average = stats.getAverage();
retval.append("shortest ").append(type).append(" pulse:").append(low)
.append(" tstates, longest ").append(type).append(" pulse:")
.append(high).append(" tstates\n");
retval.append("shortest ").append(type).append(" pulse ")
.append(String.format("%.2f", (double)low/standardPulse*100.0))
.append("% of expected, longest ").append(type)
.append(" pulse ").append(String.format("%.2f", (double)high/standardPulse*100.0))
.append("% of expected\n");
retval.append("average ").append(type).append(" pulse:").append(String.format("%.2f", average))
.append("\n");
return retval.toString();
}
示例9: testSummarizing
import java.util.LongSummaryStatistics; //导入依赖的package包/类
@Test
public void testSummarizing() {
withRandom(r -> {
long[] data = LongStreamEx.of(r, 1000, 1, Long.MAX_VALUE).toArray();
LongSummaryStatistics expected = LongStream.of(data).summaryStatistics();
LongSummaryStatistics statistics = LongStreamEx.of(data).collect(LongCollector.summarizing());
assertEquals(expected.getCount(), statistics.getCount());
assertEquals(expected.getSum(), statistics.getSum());
assertEquals(expected.getMax(), statistics.getMax());
assertEquals(expected.getMin(), statistics.getMin());
statistics = LongStreamEx.of(data).parallel().collect(LongCollector.summarizing());
assertEquals(expected.getCount(), statistics.getCount());
assertEquals(expected.getSum(), statistics.getSum());
assertEquals(expected.getMax(), statistics.getMax());
assertEquals(expected.getMin(), statistics.getMin());
});
}
示例10: counters
import java.util.LongSummaryStatistics; //导入依赖的package包/类
@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();
Assert.assertEquals(4, r.counters().count());
final LongSummaryStatistics summary = r.counters()
.filter(Functions.nameEquals("foo"))
.collect(Collectors.summarizingLong(Counter::count));
Assert.assertEquals(3L, summary.getCount());
Assert.assertEquals(16L, summary.getSum());
Assert.assertEquals(13L, summary.getMax());
}
示例11: timers
import java.util.LongSummaryStatistics; //导入依赖的package包/类
@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);
Assert.assertEquals(4, r.timers().count());
final LongSummaryStatistics countSummary = r.timers()
.filter(Functions.nameEquals("foo"))
.collect(Collectors.summarizingLong(Timer::count));
Assert.assertEquals(3L, countSummary.getCount());
Assert.assertEquals(4L, countSummary.getSum());
Assert.assertEquals(2L, countSummary.getMax());
final LongSummaryStatistics totalSummary = r.timers()
.filter(Functions.nameEquals("foo"))
.collect(Collectors.summarizingLong(Timer::totalTime));
Assert.assertEquals(3L, totalSummary.getCount());
Assert.assertEquals(16L, totalSummary.getSum());
Assert.assertEquals(13L, totalSummary.getMax());
}
示例12: distributionSummaries
import java.util.LongSummaryStatistics; //导入依赖的package包/类
@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);
Assert.assertEquals(4, r.distributionSummaries().count());
final LongSummaryStatistics countSummary = r.distributionSummaries()
.filter(Functions.nameEquals("foo"))
.collect(Collectors.summarizingLong(DistributionSummary::count));
Assert.assertEquals(3L, countSummary.getCount());
Assert.assertEquals(4L, countSummary.getSum());
Assert.assertEquals(2L, countSummary.getMax());
final LongSummaryStatistics totalSummary = r.distributionSummaries()
.filter(Functions.nameEquals("foo"))
.collect(Collectors.summarizingLong(DistributionSummary::totalAmount));
Assert.assertEquals(3L, totalSummary.getCount());
Assert.assertEquals(16L, totalSummary.getSum());
Assert.assertEquals(13L, totalSummary.getMax());
}
示例13: long_summary_stats_with_stream
import java.util.LongSummaryStatistics; //导入依赖的package包/类
@Test
public void long_summary_stats_with_stream() {
LongSummaryStatistics stats = shipments.stream()
.mapToLong((x) -> x.getCost()).summaryStatistics();
// average
assertEquals(310.25, stats.getAverage(), 0);
// count
assertEquals(4, stats.getCount(), 0);
// max
assertEquals(901.0, stats.getMax(), 0);
// min
assertEquals(45.0, stats.getMin(), 0);
// sum
assertEquals(1241.0, stats.getSum(), 0);
}
示例14: long_summary_stats_stream_reduction_target
import java.util.LongSummaryStatistics; //导入依赖的package包/类
@Test
public void long_summary_stats_stream_reduction_target() {
LongSummaryStatistics stats = shipments.stream().collect(
Collectors.summarizingLong(Shipment::getCost));
// average
assertEquals(310.25, stats.getAverage(), 0);
// count
assertEquals(4, stats.getCount(), 0);
// max
assertEquals(901.0, stats.getMax(), 0);
// min
assertEquals(45.0, stats.getMin(), 0);
// sum
assertEquals(1241.0, stats.getSum(), 0);
}
示例15: toString
import java.util.LongSummaryStatistics; //导入依赖的package包/类
public String toString() {
if (process_durations.isEmpty()) {
return null;
}
TableList list = new TableList();
LongSummaryStatistics stats = getStats();
list.addRow("entries", stats.getCount(), 1, 0, "measured (" + max_entry_count + " max)", Locale.US);
list.addRow("total time", stats.getSum(), 1000, 3, "sec", Locale.US);
list.addRow("min", stats.getMin(), 1000, 3, "sec", Locale.US);
list.addRow("average", stats.getAverage(), 1000, 3, "sec", Locale.US);
list.addRow("max", stats.getMax(), 1000, 3, "sec", Locale.US);
if (stats.getMax() != slow_duration) {
System.err.println(slow_duration);
}
if (slow_ressource_name != null) {
list.addRow("slower", slow_ressource_name);
}
return list.toString();
}