private static void saveDataFile(String location, String name, DescriptiveStatistics data, TimeUnit scale) { long conv = scale.toNanos(1); Path dst = Paths.get(location, name); try (PrintStream output = new PrintStream(dst.toString())) { // Print all values one per line Arrays.stream(data.getValues()).forEach(d -> output.println(d / conv)); } catch (FileNotFoundException e) { LOG.error("failed to write to {}", dst); } }
@Override public Void execute() { try (final DoubleStream stream = buildPrevious()) { stream.forEach(consumer); } return null; } }
default <T> void forEach(DoublePipeline pipeline, DoubleConsumer action) { requireNonNull(pipeline); requireNonNull(action); optimize(pipeline).getAsDoubleStream().forEach(action); }
@Override public void forEach(DoubleConsumer action) { finallyClose(() -> stream().forEach(action)); }
private Object getExpectedValueDoubles(double maxError, double... values) { if (values.length == 0) { return null; } QuantileDigest qdigest = new QuantileDigest(maxError); Arrays.stream(values).forEach(value -> qdigest.add(doubleToSortableLong(value))); return new SqlVarbinary(qdigest.serialize().getBytes()); }
double[] array = {1, 6, 7, 3, 3, 1, 2, 8, 9, 7, 3}; Arrays.stream(array, 3, 6).forEach((d) -> { System.out.println(d); }); OR IntStream.range(3, 6).mapToDouble(i -> array[i]).forEach(d -> { System.out.println(d); });
/** * Accept double statistics. * * @param value the value * @return the double statistics */ @javax.annotation.Nonnull public com.simiacryptus.util.data.DoubleStatistics accept(@javax.annotation.Nonnull final double[] value) { Arrays.stream(value).forEach(this::accept); return this; }
/** * Stats scalar statistics. * * @param data the data * @return the scalar statistics */ @javax.annotation.Nonnull public static com.simiacryptus.util.data.ScalarStatistics stats(@javax.annotation.Nonnull final double[] data) { @javax.annotation.Nonnull final com.simiacryptus.util.data.ScalarStatistics statistics = new PercentileStatistics(); Arrays.stream(data).forEach(statistics::add); return statistics; }
@Override public void forEach(final DoubleConsumer action) { // This is a terminal operation executeAndClose(() -> stream.forEach(action)); }
default <T> void forEach(DoublePipeline pipeline, DoubleConsumer action) { requireNonNull(pipeline); requireNonNull(action); optimize(pipeline).getAsDoubleStream().forEach(action); }
@Override public void forEach(DoubleConsumer action) { finallyClose(() -> stream().forEach(action)); }
/** * Retruns the integer bounds of a stream of doubles * @param stream the stream to compute bounds on * @return the bounds for stream, empty if no data in stream */ public static Optional<Bounds<Double>> ofDoubles(DoubleStream stream) { final OfDoubles calculator = new OfDoubles(); stream.forEach(calculator::add); return calculator.getBounds(); }
public static Map<String, String> createLatencyReportFast(Histogram histogram) { Map<String, String> fmt = new LinkedHashMap<>(); Arrays.stream(PERCENTILES).forEach(p -> { String formattedValue = formatLatencyValueAsTime((int) histogram.getValueAtPercentile(p)); fmt.put(p + "%", formattedValue); }); fmt.put("W", formatLatencyValueAsTime((int) histogram.getMaxValue())); return fmt; }
@Override public Range buildRange() { rebuild(); Range range = new Range(); range.union(minValue, Double.NaN); range.union(maxValue, Double.NaN); Arrays.stream(freqTable).sequential().forEach(t -> range.union(Double.NaN, t)); range.union(Double.NaN, 0); return range; }
@Override protected Factory<DoubleSummary> factory() { return () -> { final Random random = RandomRegistry.getRandom(); final DoubleSummaryStatistics statistics = new DoubleSummaryStatistics(); IntStream.range(0, 100) .mapToDouble(i -> random.nextDouble()) .forEach(statistics); return DoubleSummary.of(statistics); }; }
private Object getExpectedValueDoubles(double maxError, double... values) { if (values.length == 0) { return null; } QuantileDigest qdigest = new QuantileDigest(maxError); Arrays.stream(values).forEach(value -> qdigest.add(doubleToSortableLong(value))); return new SqlVarbinary(qdigest.serialize().getBytes()); }
private Object getExpectedValueDoubles(double maxError, double... values) { if (values.length == 0) { return null; } QuantileDigest qdigest = new QuantileDigest(maxError); Arrays.stream(values).forEach(value -> qdigest.add(doubleToSortableLong(value))); return new SqlVarbinary(qdigest.serialize().getBytes()); }
public void testDoubleToArray() { Cache<Double, String> cache = getCache(0); int range = 10; // First populate the cache with a bunch of values DoubleStream.iterate(0.0, d -> d + .5).limit(10).boxed().forEach(i -> cache.put(i, i + "-value")); assertEquals(range, cache.size()); CacheSet<Map.Entry<Double, String>> entrySet = cache.entrySet(); double[] array = createStream(entrySet).mapToDouble(toDouble).toArray(); assertEquals(cache.size(), array.length); Spliterator.OfDouble spliterator = Spliterators.spliterator(array, Spliterator.DISTINCT); StreamSupport.doubleStream(spliterator, true).forEach(e -> assertTrue(cache.containsKey(e))); }