@Override public LongSummaryStatistics execute() { try (final LongStream stream = buildPrevious()) { return stream.summaryStatistics(); } } }
@Override public Statistics statistics() { return createStatistics(durations.stream().mapToLong(Duration::toNanos).summaryStatistics()); }
default LongSummaryStatistics summaryStatistics(LongPipeline pipeline) { requireNonNull(pipeline); return optimize(pipeline).getAsLongStream().summaryStatistics(); }
private static String formatNanos(List<Long> list) { LongSummaryStatistics stats = list.stream().mapToLong(Long::new).summaryStatistics(); return String.format("Min: %8s Max: %8s Avg: %8s Sum: %8s", succinctNanos(stats.getMin() == Long.MAX_VALUE ? 0 : stats.getMin()), succinctNanos(stats.getMax() == Long.MIN_VALUE ? 0 : stats.getMax()), succinctNanos((long) stats.getAverage()), succinctNanos(stats.getSum())); } }
@Override public LongSummaryStatistics summaryStatistics() { return stream.summaryStatistics(); }
public LongSummaryStatistics buildTimeStatistics() { return this.buildTimes. stream(). mapToLong(t -> t). summaryStatistics(); }
/** * @param collection * The collection of items * @return A state object for collecting statistics such as count, min, max, sum, and average. */ public static LongSummaryStatistics summarizingLong(final Collection<Long> collection) { return collection.stream().mapToLong(value -> value).summaryStatistics(); }
public LongSummaryStatistics warSizeStatistics() { return this.warSizes.stream().mapToLong(s -> s).summaryStatistics(); }
private LongSummaryStatistics benchmark(final String testName, final Runnable methodToTest, int samples) { long[] timing = new long[samples]; for (int i = 0; i < samples; i++) { long start = System.currentTimeMillis(); methodToTest.run(); timing[i] = System.currentTimeMillis() - start; } final LongSummaryStatistics stats = Arrays.stream(timing).summaryStatistics(); System.out.println(testName + ": " + stats); return stats; }
/** * Get summary statistic from an object collection. An example to get summary of age from a * Person list would be (suppose a person can live longer than 2^31 - 1) * <p> * <code> {@literal LongSummaryStatistics stat = StatisticUtils.summarizingLong(list, x->x.getAge());} </code> * </p> * * @param collection * The collection of items * @param function * You need to specify the function to get long value for each object T * @param <T> * The type of the statistic * @return A state object for collecting statistics such as count, min, max, sum, and average. */ public static <T> LongSummaryStatistics summarizingLong(final Collection<T> collection, final ToLongFunction<? super T> function) { return collection.stream().mapToLong(function).summaryStatistics(); }
@Override public LongSummaryStatistics summaryStatistics() { // This is a terminal operation return evalAndclose(() -> stream.summaryStatistics()); }
@Override public Statistics statistics() { return createStatistics(durations.stream().mapToLong(Duration::toNanos).summaryStatistics()); }
default LongSummaryStatistics summaryStatistics(LongPipeline pipeline) { requireNonNull(pipeline); return optimize(pipeline).getAsLongStream().summaryStatistics(); }
int numbers[] = new int[5]; for(int count = 0; count < numbers.length; count++){ System.out.print("Please enter a number: "); int number=s.nextInt(); numbers[count] = number; } LongSummaryStatistics statistics = Arrays.stream(numbers).asLongStream().summaryStatistics(); System.out.println("Highest: " + statistics.getMax()); System.out.println("Lowest: " + statistics.getMin()); System.out.println("The average of all number is: " + statistics.getAverage());
/** * Plot plot canvas. * * @param history the history * @return the plot canvas */ public static PlotCanvas plotTime(@Nonnull final List<StepRecord> history) { try { final LongSummaryStatistics timeStats = history.stream().mapToLong(x -> x.epochTime).summaryStatistics(); final DoubleSummaryStatistics valueStats = history.stream().mapToDouble(x -> x.fitness).filter(x -> x > 0).summaryStatistics(); @Nonnull final PlotCanvas plot = ScatterPlot.plot(history.stream().map(step -> new double[]{ (step.epochTime - timeStats.getMin()) / 1000.0, Math.log10(Math.max(valueStats.getMin(), step.fitness))}) .filter(x -> Arrays.stream(x).allMatch(Double::isFinite)) .toArray(i -> new double[i][])); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Time", "log10(Fitness)"); plot.setSize(600, 400); return plot; } catch (@Nonnull final Exception e) { e.printStackTrace(System.out); return null; } }
/** * Plot plot canvas. * * @param history the history * @return the plot canvas */ public static PlotCanvas plotTime(@Nonnull final List<StepRecord> history) { try { final LongSummaryStatistics timeStats = history.stream().mapToLong(x -> x.epochTime).summaryStatistics(); final DoubleSummaryStatistics valueStats = history.stream().mapToDouble(x -> x.fitness).filter(x -> x > 0).summaryStatistics(); @Nonnull final PlotCanvas plot = ScatterPlot.plot(history.stream().map(step -> new double[]{ (step.epochTime - timeStats.getMin()) / 1000.0, Math.log10(Math.max(valueStats.getMin(), step.fitness))}) .filter(x -> Arrays.stream(x).allMatch(Double::isFinite)) .toArray(i -> new double[i][])); plot.setTitle("Convergence Plot"); plot.setAxisLabels("Time", "log10(Fitness)"); plot.setSize(600, 400); return plot; } catch (@Nonnull final Exception e) { e.printStackTrace(System.out); return null; } }
/** * Perform an asynchronous summaryStatistics operation * @see java.util.stream.Stream#mapToLong(ToLongFunction) * @see java.util.stream.LongStream#summaryStatistics() * */ default CompletableFuture<LongSummaryStatistics> summaryStatisticsLong(ToLongFunction<? super T> fn){ return CompletableFuture.supplyAsync(()->getStream() .flatMapToLong(t-> LongStream.of(fn.applyAsLong(t))) .summaryStatistics(),getExec()); } }
/** * This test executes a series of metadata operations on streams and scopes to verify their correct behavior. This * includes the creation and deletion of multiple scopes both in correct and incorrect situations. Moreover, for * each scope, the test creates a range of streams and tries to create, update, seal and delete them in correct and * incorrect situations. The test also performs metadata operation on empty and non-empty streams. */ @Test public void testStreamsAndScopesManagement() { // Perform management tests with Streams and Scopes. for (int i = 0; i < TEST_ITERATIONS; i++) { log.info("Stream and scope management test in iteration {}.", i); testStreamScopeManagementIteration(); } // Provide some performance information of Stream/Scope metadata operations. for (String perfKey : controllerPerfStats.keySet()) { log.info("Performance of {}: {}", perfKey, controllerPerfStats.get(perfKey).stream().mapToLong(x -> x).summaryStatistics()); } log.debug("Scope and Stream management test passed."); }
private static String formatNanos(List<Long> list) { LongSummaryStatistics stats = list.stream().mapToLong(Long::new).summaryStatistics(); return String.format("Min: %8s Max: %8s Avg: %8s Sum: %8s", succinctNanos(stats.getMin() == Long.MAX_VALUE ? 0 : stats.getMin()), succinctNanos(stats.getMax() == Long.MIN_VALUE ? 0 : stats.getMax()), succinctNanos((long) stats.getAverage()), succinctNanos(stats.getSum())); } }
private static String formatNanos(List<Long> list) { LongSummaryStatistics stats = list.stream().mapToLong(Long::new).summaryStatistics(); return String.format("Min: %8s Max: %8s Avg: %8s Sum: %8s", succinctNanos(stats.getMin() == Long.MAX_VALUE ? 0 : stats.getMin()), succinctNanos(stats.getMax() == Long.MIN_VALUE ? 0 : stats.getMax()), succinctNanos((long) stats.getAverage()), succinctNanos(stats.getSum())); } }