/** * Returns a sequential ordered {@code DoubleStreamEx} whose elements are * the specified float values casted to double. * * @param elements the elements of the new stream * @return the new stream * @since 0.2.0 */ public static DoubleStreamEx of(float... elements) { return of(elements, 0, elements.length); }
/** * Returns a sequential {@code DoubleStreamEx} containing a single element. * * @param element the single element * @return a singleton sequential stream */ public static DoubleStreamEx of(double element) { return of(new ConstSpliterator.OfDouble(element, 1, true)); }
/** * Returns an empty sequential {@code DoubleStreamEx}. * * @return an empty sequential stream */ public static DoubleStreamEx empty() { return of(Spliterators.emptyDoubleSpliterator()); }
/** * Returns the stream which covers all the elements emitted by this * emitter. * * @return the new stream */ default DoubleStreamEx stream() { return of(spliterator()); } }
/** * Returns a sequential ordered {@code DoubleStreamEx} whose elements are * the specified values. * * @param elements the elements of the new stream * @return the new stream */ public static DoubleStreamEx of(double... elements) { return of(Arrays.spliterator(elements)); }
/** * Returns a sequential unordered {@code DoubleStreamEx} of given length * which elements are equal to supplied value. * * @param value the constant value * @param length the length of the stream * @return a new {@code DoubleStreamEx} * @since 0.1.2 */ public static DoubleStreamEx constant(double value, long length) { return of(new ConstSpliterator.OfDouble(value, length, false)); }
/** * Returns a sequential, ordered {@link DoubleStreamEx} created from given * {@link java.util.PrimitiveIterator.OfDouble}. * * <p> * This method is roughly equivalent to * {@code DoubleStreamEx.of(Spliterators.spliteratorUnknownSize(iterator, ORDERED))} * , but may show better performance for parallel processing. * * <p> * Use this method only if you cannot provide better Stream source. * * @param iterator an iterator to create the stream from. * @return the new stream * @since 0.5.1 */ public static DoubleStreamEx of(PrimitiveIterator.OfDouble iterator) { return of(new UnknownSizeSpliterator.USOfDouble(iterator)); }
/** * Returns a sequential {@link DoubleStreamEx} with the specified range of * the specified array as its source. * * @param array the array, assumed to be unmodified during use * @param startInclusive the first index to cover, inclusive * @param endExclusive index immediately past the last index to cover * @return an {@code DoubleStreamEx} for the array range * @throws ArrayIndexOutOfBoundsException if {@code startInclusive} is * negative, {@code endExclusive} is less than * {@code startInclusive}, or {@code endExclusive} is greater than * the array size * @since 0.1.1 * @see Arrays#stream(double[], int, int) */ public static DoubleStreamEx of(double[] array, int startInclusive, int endExclusive) { return of(Arrays.spliterator(array, startInclusive, endExclusive)); }
/** * Returns a sequential {@code DoubleStreamEx} containing an * {@link OptionalDouble} value, if present, otherwise returns an empty * {@code DoubleStreamEx}. * * @param optional the optional to create a stream of * @return a stream with an {@code OptionalDouble} value if present, * otherwise an empty stream * @since 0.1.1 */ public static DoubleStreamEx of(OptionalDouble optional) { return optional.isPresent() ? of(optional.getAsDouble()) : empty(); }
return of(spliterator);
/** * Returns a sequential {@code DoubleStreamEx} containing the results of * applying the given function to the corresponding pairs of values in given * two arrays. * * @param first the first array * @param second the second array * @param mapper a non-interfering, stateless function to apply to each pair * of the corresponding array elements. * @return a new {@code DoubleStreamEx} * @throws IllegalArgumentException if length of the arrays differs. * @since 0.2.1 */ public static DoubleStreamEx zip(double[] first, double[] second, DoubleBinaryOperator mapper) { return of(new RangeBasedSpliterator.ZipDouble(0, checkLength(first.length, second.length), mapper, first, second)); }
/** * Returns a sequential {@link DoubleStreamEx} with the specified range of * the specified array as its source. Array values will be casted to double. * * @param array the array, assumed to be unmodified during use * @param startInclusive the first index to cover, inclusive * @param endExclusive index immediately past the last index to cover * @return an {@code IntStreamEx} for the array range * @throws ArrayIndexOutOfBoundsException if {@code startInclusive} is * negative, {@code endExclusive} is less than * {@code startInclusive}, or {@code endExclusive} is greater than * the array size * @since 0.2.0 */ public static DoubleStreamEx of(float[] array, int startInclusive, int endExclusive) { rangeCheck(array.length, startInclusive, endExclusive); return of(new RangeBasedSpliterator.OfFloat(startInclusive, endExclusive, array)); }
private void writeMetrics(final JsonNode ownerNode, final XSSFRow row) { AtomicInteger counter = new AtomicInteger(); ownerNode.get("metrics").fields() .forEachRemaining(entry -> { entry.getValue().get("versions").fields() .forEachRemaining(vEntry -> { final Cell vCell = row.createCell(3 + counter.getAndIncrement(), CellType.NUMERIC); double value = vEntry.getValue().get("value").asDouble(); vCell.setCellValue(value); }); final double [] delta = DoubleStreamEx.of( StreamSupport.stream(entry.getValue().get("versions").spliterator(), false) .mapToDouble(vNode -> vNode.get("value").asDouble())) .pairMap( (a, b) -> b - a).toArray(); stream(delta).forEach(v -> { final Cell vCell = row.createCell(3 + counter.getAndIncrement(), CellType.NUMERIC); vCell.setCellValue(v); if (v == 0) { vCell.setCellStyle(yellow); } else if (v > 0) { vCell.setCellStyle(green); } else { vCell.setCellStyle(red); } }); }); }
/** * Returns a new stream containing all the elements of the original stream interspersed with * given delimiter. * * <p> * For example, {@code DoubleStreamEx.of(1, 2, 3).intersperse(4)} will yield a stream containing * five elements: 1, 4, 2, 4, 3. * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate operation</a>. * * @param delimiter a delimiter to be inserted between each pair of elements * @return the new stream * @since 0.6.6 */ public DoubleStreamEx intersperse(int delimiter) { return new DoubleStreamEx(stream().flatMap(s -> DoubleStreamEx.of(delimiter, s)).skip(1), context); }