java.util.IntSummaryStatistics Java Examples
The following examples show how to use
java.util.IntSummaryStatistics.
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: HighFrequencyDetector.java From ffwd with Apache License 2.0 | 6 votes |
private int computeTimeDelta(List<Metric> list) { int size = list.size(); IntSummaryStatistics stats = IntStream.range(1, size) .map( x -> (int) (list.get(size - x).getTime().getTime() - list.get(size - x - 1).getTime().getTime())) .filter(d -> (d >= 0 && d < minFrequencyMillisAllowed)) .summaryStatistics(); int result = -1; /** * In order to be marked as high frequency metric the number of points * should be above the BURST_THRESHOLD. * It ignores any small bursts of high frequency metrics. */ if (stats.getCount() > BURST_THRESHOLD) { // uses minimal delta time from all consecutive data points result = stats.getMin(); log.info("stats: " + stats); } return result; }
Example #2
Source File: CollectAndSummaryStatisticsTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public void testIntStatistics() { List<IntSummaryStatistics> instances = new ArrayList<>(); instances.add(countTo(1000).stream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).stream().mapToInt(i -> i).summaryStatistics()); instances.add(countTo(1000).stream().mapToInt(i -> i).collect(IntSummaryStatistics::new, IntSummaryStatistics::accept, IntSummaryStatistics::combine)); instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).parallelStream().mapToInt(i -> i).summaryStatistics()); instances.add(countTo(1000).parallelStream().mapToInt(i -> i).collect(IntSummaryStatistics::new, IntSummaryStatistics::accept, IntSummaryStatistics::combine)); for (IntSummaryStatistics stats : instances) { assertEquals(stats.getCount(), 1000); assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum()); assertEquals(stats.getAverage(), (double) stats.getSum() / stats.getCount()); assertEquals(stats.getMax(), 1000); assertEquals(stats.getMin(), 1); } }
Example #3
Source File: ConcurrentTestRunnerTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void runRandomlyDistributedReactorOperationsShouldRunAllOperationsEvenly() throws ExecutionException, InterruptedException { AtomicInteger firstOperationRuns = new AtomicInteger(0); AtomicInteger secondOperationRuns = new AtomicInteger(0); AtomicInteger thirdOperationRuns = new AtomicInteger(0); int threadCount = 10; int operationCount = 1000; ConcurrentTestRunner.builder() .randomlyDistributedReactorOperations( (threadNumber, step) -> Mono.fromRunnable(firstOperationRuns::incrementAndGet), (threadNumber, step) -> Mono.fromRunnable(secondOperationRuns::incrementAndGet), (threadNumber, step) -> Mono.fromRunnable(thirdOperationRuns::incrementAndGet)) .threadCount(threadCount) .operationCount(operationCount) .runSuccessfullyWithin(Duration.ofMinutes(1)); IntSummaryStatistics statistics = IntStream.of(firstOperationRuns.get(), secondOperationRuns.get(), thirdOperationRuns.get()).summaryStatistics(); int min = statistics.getMin(); int max = statistics.getMax(); assertThat(max - min).isLessThan((threadCount * operationCount) * 5 / 100); }
Example #4
Source File: ConcurrentTestRunnerTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void runRandomlyDistributedOperationsShouldRunAllOperationsEvenly() throws ExecutionException, InterruptedException { AtomicInteger firstOperationRuns = new AtomicInteger(0); AtomicInteger secondOperationRuns = new AtomicInteger(0); AtomicInteger thirdOperationRuns = new AtomicInteger(0); int threadCount = 10; int operationCount = 1000; ConcurrentTestRunner.builder() .randomlyDistributedOperations( (threadNumber, step) -> firstOperationRuns.incrementAndGet(), (threadNumber, step) -> secondOperationRuns.incrementAndGet(), (threadNumber, step) -> thirdOperationRuns.incrementAndGet()) .threadCount(threadCount) .operationCount(operationCount) .runSuccessfullyWithin(Duration.ofMinutes(1)); IntSummaryStatistics statistics = IntStream.of(firstOperationRuns.get(), secondOperationRuns.get(), thirdOperationRuns.get()).summaryStatistics(); int min = statistics.getMin(); int max = statistics.getMax(); assertThat(max - min).isLessThan((threadCount * operationCount) * 5 / 100); }
Example #5
Source File: IntCollectorTest.java From streamex with Apache License 2.0 | 6 votes |
@Test public void testSummarizing() { withRandom(r -> { int[] data = IntStreamEx.of(r, 1000, 1, Integer.MAX_VALUE).toArray(); IntSummaryStatistics expected = IntStream.of(data).summaryStatistics(); IntSummaryStatistics statistics = IntStreamEx.of(data).collect(IntCollector.summarizing()); assertEquals(expected.getCount(), statistics.getCount()); assertEquals(expected.getSum(), statistics.getSum()); assertEquals(expected.getMax(), statistics.getMax()); assertEquals(expected.getMin(), statistics.getMin()); statistics = IntStreamEx.of(data).parallel().collect(IntCollector.summarizing()); assertEquals(expected.getCount(), statistics.getCount()); assertEquals(expected.getSum(), statistics.getSum()); assertEquals(expected.getMax(), statistics.getMax()); assertEquals(expected.getMin(), statistics.getMin()); }); }
Example #6
Source File: CollectAndSummaryStatisticsTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public void testIntStatistics() { List<IntSummaryStatistics> instances = new ArrayList<>(); instances.add(countTo(1000).stream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).stream().mapToInt(i -> i).summaryStatistics()); instances.add(countTo(1000).stream().mapToInt(i -> i).collect(IntSummaryStatistics::new, IntSummaryStatistics::accept, IntSummaryStatistics::combine)); instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).parallelStream().mapToInt(i -> i).summaryStatistics()); instances.add(countTo(1000).parallelStream().mapToInt(i -> i).collect(IntSummaryStatistics::new, IntSummaryStatistics::accept, IntSummaryStatistics::combine)); for (IntSummaryStatistics stats : instances) { assertEquals(stats.getCount(), 1000); assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum()); assertEquals(stats.getAverage(), (double) stats.getSum() / stats.getCount()); assertEquals(stats.getMax(), 1000); assertEquals(stats.getMin(), 1); } }
Example #7
Source File: IntSummaryStatisticsExample.java From levelup-java-examples with Apache License 2.0 | 6 votes |
@Test public void int_summary_stats_with_stream() { IntSummaryStatistics stats = orderEntries.stream() .mapToInt((x) -> x.getAmount()).summaryStatistics(); // average assertEquals(13.5, stats.getAverage(), 0); // count assertEquals(4, stats.getCount(), 0); // max assertEquals(18, stats.getMax(), 0); // min assertEquals(10, stats.getMin(), 0); // sum assertEquals(54, stats.getSum(), 0); }
Example #8
Source File: CollectAndSummaryStatisticsTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void testIntStatistics() { List<IntSummaryStatistics> instances = new ArrayList<>(); instances.add(countTo(1000).stream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).stream().mapToInt(i -> i).summaryStatistics()); instances.add(countTo(1000).stream().mapToInt(i -> i).collect(IntSummaryStatistics::new, IntSummaryStatistics::accept, IntSummaryStatistics::combine)); instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).parallelStream().mapToInt(i -> i).summaryStatistics()); instances.add(countTo(1000).parallelStream().mapToInt(i -> i).collect(IntSummaryStatistics::new, IntSummaryStatistics::accept, IntSummaryStatistics::combine)); for (IntSummaryStatistics stats : instances) { assertEquals(stats.getCount(), 1000); assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum()); assertEquals(stats.getAverage(), (double) stats.getSum() / stats.getCount()); assertEquals(stats.getMax(), 1000); assertEquals(stats.getMin(), 1); } }
Example #9
Source File: FirstDdemo.java From javabase with Apache License 2.0 | 5 votes |
private static void getMax() { List<Integer> primes = Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19, 23, 29); IntSummaryStatistics stats = primes.stream().mapToInt((x) -> x) .summaryStatistics(); System.out.println("Highest prime number in List : " + stats.getMax()); System.out.println("Lowest prime number in List : " + stats.getMin()); System.out.println("Sum of all prime numbers : " + stats.getSum()); System.out.println("Average of all prime numbers : " + stats.getAverage()); }
Example #10
Source File: Primitives.java From java-8-lambdas-exercises with MIT License | 5 votes |
public static void printTrackLengthStatistics(Album album) { IntSummaryStatistics trackLengthStats = album.getTracks() .mapToInt(track -> track.getLength()) .summaryStatistics(); System.out.printf("Max: %d, Min: %d, Ave: %f, Sum: %d", trackLengthStats.getMax(), trackLengthStats.getMin(), trackLengthStats.getAverage(), trackLengthStats.getSum()); }
Example #11
Source File: SummaryStatisticsTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void testIntStatistics() { List<IntSummaryStatistics> instances = new ArrayList<>(); instances.add(countTo(1000).stream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).stream().mapToInt(i -> i).summaryStatistics()); instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).parallelStream().mapToInt(i -> i).summaryStatistics()); for (IntSummaryStatistics stats : instances) { assertEquals(stats.getCount(), 1000); assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum()); assertEquals(stats.getMax(), 1000); assertEquals(stats.getMin(), 1); } }
Example #12
Source File: SummaryStatisticsTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public void testIntStatistics() { List<IntSummaryStatistics> instances = new ArrayList<>(); instances.add(countTo(1000).stream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).stream().mapToInt(i -> i).summaryStatistics()); instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).parallelStream().mapToInt(i -> i).summaryStatistics()); for (IntSummaryStatistics stats : instances) { assertEquals(stats.getCount(), 1000); assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum()); assertEquals(stats.getMax(), 1000); assertEquals(stats.getMin(), 1); } }
Example #13
Source File: SummaryStatisticsTest.java From hottub with GNU General Public License v2.0 | 5 votes |
public void testIntStatistics() { List<IntSummaryStatistics> instances = new ArrayList<>(); instances.add(countTo(1000).stream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).stream().mapToInt(i -> i).summaryStatistics()); instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).parallelStream().mapToInt(i -> i).summaryStatistics()); for (IntSummaryStatistics stats : instances) { assertEquals(stats.getCount(), 1000); assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum()); assertEquals(stats.getMax(), 1000); assertEquals(stats.getMin(), 1); } }
Example #14
Source File: HashMapVisualiser.java From map-visualiser with MIT License | 5 votes |
public void visualise(final HashMap<?, ?> map) { Object[] table = (Object[]) Type.get(tableField, map); console.printf( "Size: %d, Resize: %s, Bin Count: %d%n", map.size(), Type.get(thresholdField, map), table.length); final IntSummaryStatistics collisions = Stream.of(table) .mapToInt(row -> { if (row == null) { console.println("[]"); return 0; } switch (row.getClass().getSimpleName()) { case "TreeNode": return visualiseTree(row); case "Node": return visualiseList(row); default: throw new IllegalArgumentException("Unknown type of row"); } }) .summaryStatistics(); console.printf( "Collisions: Max: %d, Ave: %s, Total: %d%n", collisions.getMax(), collisions.getAverage(), collisions.getSum()); }
Example #15
Source File: PlanFragmentStats.java From dremio-oss with Apache License 2.0 | 5 votes |
public PlanFragmentStats() { sizeByMajorSpecific = new HashMap<>(); sizeByMinorSpecific = new HashMap<>(); sizeByMinorAttr = new HashMap<>(); sizeBySharedAttr = new HashMap<>(); combinedSize = new IntSummaryStatistics(); }
Example #16
Source File: ReaderCheckpointTest.java From pravega with Apache License 2.0 | 5 votes |
private void verifyEvents(final List<EventRead<Integer>> events, int startInclusive, int endExclusive) { Supplier<java.util.stream.Stream<Integer>> streamSupplier = () -> events.stream().map(EventRead::getEvent).sorted(); IntSummaryStatistics stats = streamSupplier.get().collect(Collectors.summarizingInt(value -> value)); assertTrue(String.format("Check for first event: %d, %d", stats.getMin(), startInclusive), stats.getMin() == startInclusive); assertTrue(String.format("Check for last event: %d, %d", stats.getMax(), endExclusive), stats.getMax() == endExclusive - 1); //Check for missing events assertEquals(String.format("Check for number of events: %d, %d, %d", endExclusive, startInclusive, stats.getCount()), endExclusive - startInclusive, stats.getCount()); assertEquals(String.format("Check for duplicate events: %d, %d, %d", endExclusive, startInclusive, streamSupplier.get().distinct().count()), endExclusive - startInclusive, streamSupplier.get().distinct().count()); }
Example #17
Source File: Streams10.java From java8-tutorial with MIT License | 5 votes |
private static void test4(List<Person> persons) { IntSummaryStatistics ageSummary = persons .stream() .collect(Collectors.summarizingInt(p -> p.age)); System.out.println(ageSummary); // IntSummaryStatistics{count=4, sum=76, min=12, average=19,000000, max=23} }
Example #18
Source File: Java8GroupingByCollectorUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenAListOfPosts_whenGroupedByTypeAndSummarizingLikes_thenGetAMapBetweenTypeAndSummary() { Map<BlogPostType, IntSummaryStatistics> likeStatisticsPerType = posts.stream() .collect(groupingBy(BlogPost::getType, summarizingInt(BlogPost::getLikes))); IntSummaryStatistics newsLikeStatistics = likeStatisticsPerType.get(BlogPostType.NEWS); assertEquals(2, newsLikeStatistics.getCount()); assertEquals(50, newsLikeStatistics.getSum()); assertEquals(25.0, newsLikeStatistics.getAverage(), 0.001); assertEquals(35, newsLikeStatistics.getMax()); assertEquals(15, newsLikeStatistics.getMin()); }
Example #19
Source File: SummaryStatisticsTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public void testIntStatistics() { List<IntSummaryStatistics> instances = new ArrayList<>(); instances.add(countTo(1000).stream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).stream().mapToInt(i -> i).summaryStatistics()); instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).parallelStream().mapToInt(i -> i).summaryStatistics()); for (IntSummaryStatistics stats : instances) { assertEquals(stats.getCount(), 1000); assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum()); assertEquals(stats.getMax(), 1000); assertEquals(stats.getMin(), 1); } }
Example #20
Source File: FormationType.java From megamek with GNU General Public License v2.0 | 5 votes |
private static IntSummaryStatistics damageAtRangeStats(MechSummary ms, int range) { List<Integer> retVal = new ArrayList<>(); for (int i = 0; i < ms.getEquipmentNames().size(); i++) { if (EquipmentType.get(ms.getEquipmentNames().get(i)) instanceof WeaponType) { final WeaponType weapon = (WeaponType)EquipmentType.get(ms.getEquipmentNames().get(i)); if (weapon.getLongRange() < range) { continue; } int damage = 0; if (weapon.getAmmoType() != AmmoType.T_NA) { Optional<EquipmentType> ammo = ms.getEquipmentNames().stream() .map(name -> EquipmentType.get(name)) .filter(eq -> eq instanceof AmmoType && ((AmmoType)eq).getAmmoType() == weapon.getAmmoType() && ((AmmoType)eq).getRackSize() == weapon.getRackSize()) .findFirst(); if (ammo.isPresent()) { damage = ((AmmoType)ammo.get()).getDamagePerShot() * Math.max(1, ((AmmoType)ammo.get()).getRackSize()); } } else { damage = weapon.getDamage(range); } if (damage > 0) { for (int j = 0; j < ms.getEquipmentQuantities().get(i); j++) { retVal.add(damage); } } } } return retVal.stream().mapToInt(Integer::intValue).summaryStatistics(); }
Example #21
Source File: Java8TestCase.java From symja_android_library with GNU General Public License v3.0 | 5 votes |
public void testStatistics() { IAST ast = (IAST) F.List.of(10, 11, 12, 13, 14, 15, 16, 17, 18, 19); // calculating sum using reduce terminal operator int value = ast.stream() // .mapToInt(IExpr::toIntDefault) // .reduce(0, (total, currentValue) -> total + currentValue); assertEquals(145, value); value = ast.stream() // .mapToInt(IExpr::toIntDefault) // .sum(); assertEquals(145, value); long longValue = ast.stream() // .mapToInt(IExpr::toIntDefault) // .count(); assertEquals(10, longValue); IntSummaryStatistics ageStatistics = ast.stream() // .mapToInt(IExpr::toIntDefault) // .summaryStatistics(); assertEquals(14.5, ageStatistics.getAverage()); assertEquals(10, ageStatistics.getCount()); assertEquals(19, ageStatistics.getMax()); assertEquals(10, ageStatistics.getMin()); assertEquals(145, ageStatistics.getSum()); }
Example #22
Source File: CollectAndSummaryStatisticsTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public void testIntCollectNull() { checkNPE(() -> IntStream.of(1).collect(null, IntSummaryStatistics::accept, IntSummaryStatistics::combine)); checkNPE(() -> IntStream.of(1).collect(IntSummaryStatistics::new, null, IntSummaryStatistics::combine)); checkNPE(() -> IntStream.of(1).collect(IntSummaryStatistics::new, IntSummaryStatistics::accept, null)); }
Example #23
Source File: IntSummaryStatisticsTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_empty() { IntSummaryStatistics iss = new IntSummaryStatistics(); assertEquals(0, iss.getCount()); assertEquals(0, iss.getSum()); assertEquals(0.0d, iss.getAverage()); assertEquals(Integer.MAX_VALUE, iss.getMin()); assertEquals(Integer.MIN_VALUE, iss.getMax()); }
Example #24
Source File: CollectAndSummaryStatisticsTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void testIntCollectNull() { checkNPE(() -> IntStream.of(1).collect(null, IntSummaryStatistics::accept, IntSummaryStatistics::combine)); checkNPE(() -> IntStream.of(1).collect(IntSummaryStatistics::new, null, IntSummaryStatistics::combine)); checkNPE(() -> IntStream.of(1).collect(IntSummaryStatistics::new, IntSummaryStatistics::accept, null)); }
Example #25
Source File: IntSummaryStatisticsTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_combine() { IntSummaryStatistics iss1 = getIntSummaryStatisticsData2(); IntSummaryStatistics issCombined = getIntSummaryStatisticsData1(); issCombined.combine(iss1); assertEquals(12, issCombined.getCount()); assertEquals(118, issCombined.getSum()); assertEquals(100, issCombined.getMax()); assertEquals(-5, issCombined.getMin()); assertEquals(9.833333d, issCombined.getAverage(), 1E-6); }
Example #26
Source File: GroupbyTest.java From spring-boot-cookbook with Apache License 2.0 | 5 votes |
@Test public void test() { List<String> strings = Arrays.asList("a", "bb", "cc", "ddd"); Map<Integer, IntSummaryStatistics> result = strings.stream() .collect(groupingBy(String::length, summarizingInt(String::hashCode))); System.out.println(result); }
Example #27
Source File: IntSummaryStatisticsTest.java From j2objc with Apache License 2.0 | 5 votes |
private static IntSummaryStatistics getIntSummaryStatisticsData1() { IntSummaryStatistics iss = new IntSummaryStatistics(); for (int value : data1) { iss.accept(value); } return iss; }
Example #28
Source File: Primitives.java From https-github.com-RichardWarburton-java-8-Lambdas-exercises with MIT License | 5 votes |
public static void printTrackLengthStatistics(Album album) { IntSummaryStatistics trackLengthStats = album.getTracks() .mapToInt(track -> track.getLength()) .summaryStatistics(); System.out.printf("Max: %d, Min: %d, Ave: %f, Sum: %d", trackLengthStats.getMax(), trackLengthStats.getMin(), trackLengthStats.getAverage(), trackLengthStats.getSum()); }
Example #29
Source File: IntSummaryStatisticsTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_accept() { IntSummaryStatistics iss = new IntSummaryStatistics(); iss.accept(5); assertEquals(1, iss.getCount()); assertEquals(5, iss.getSum()); iss.accept(10); assertEquals(2, iss.getCount()); assertEquals(15, iss.getSum()); }
Example #30
Source File: SummaryStatisticsTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void testIntStatistics() { List<IntSummaryStatistics> instances = new ArrayList<>(); instances.add(countTo(1000).stream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).stream().mapToInt(i -> i).summaryStatistics()); instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingInt(i -> i))); instances.add(countTo(1000).parallelStream().mapToInt(i -> i).summaryStatistics()); for (IntSummaryStatistics stats : instances) { assertEquals(stats.getCount(), 1000); assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum()); assertEquals(stats.getMax(), 1000); assertEquals(stats.getMin(), 1); } }