/** * 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); }
@Override public DoubleStreamEx distinct() { return new DoubleStreamEx(stream().distinct(), context); }
@Override public boolean noneMatch(DoublePredicate predicate) { return !anyMatch(predicate); }
/** * Returns an {@link OptionalDouble} describing the first element of this * stream, which matches given predicate, or an empty {@code OptionalDouble} * if there's no matching element. * * <p> * This is a short-circuiting terminal operation. * * @param predicate a * <a href="package-summary.html#NonInterference">non-interfering * </a>, <a href="package-summary.html#Statelessness">stateless</a> * predicate which returned value should match * @return an {@code OptionalDouble} describing the first matching element * of this stream, or an empty {@code OptionalDouble} if there's no * matching element * @see #findFirst() */ public OptionalDouble findFirst(DoublePredicate predicate) { return filter(predicate).findFirst(); }
/** * Returns an {@link OptionalDouble} describing some element of the stream, * which matches given predicate, or an empty {@code OptionalDouble} if * there's no matching element. * * <p> * This is a short-circuiting terminal operation. * * <p> * The behavior of this operation is explicitly nondeterministic; it is free * to select any element in the stream. This is to allow for maximal * performance in parallel operations; the cost is that multiple invocations * on the same source may not return the same result. (If a stable result is * desired, use {@link #findFirst(DoublePredicate)} instead.) * * @param predicate a * <a href="package-summary.html#NonInterference">non-interfering * </a>, <a href="package-summary.html#Statelessness">stateless</a> * predicate which returned value should match * @return an {@code OptionalDouble} describing some matching element of * this stream, or an empty {@code OptionalDouble} if there's no * matching element * @see #findAny() * @see #findFirst(DoublePredicate) */ public OptionalDouble findAny(DoublePredicate predicate) { return filter(predicate).findAny(); }
/** * 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); }
DoubleStreamEx callWhile(DoubleStreamEx stream, DoublePredicate predicate, boolean drop) { return stream.delegate(new TakeDrop.TDOfDouble(stream.spliterator(), drop, false, predicate)); }
Spliterator.OfDouble spliterator = (isParallel() ? StreamSupport.doubleStream(spliterator(), false) : stream()) .skip(n).spliterator(); return delegate(spliterator);
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 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(); }
/** * Returns a sequential {@link DoubleStreamEx} created from given * {@link java.util.Spliterator.OfDouble}. * * @param spliterator a spliterator to create the stream from. * @return the new stream * @since 0.3.4 */ public static DoubleStreamEx of(Spliterator.OfDouble spliterator) { return new DoubleStreamEx(spliterator, StreamContext.SEQUENTIAL); }
@Override public DoubleSummaryStatistics summaryStatistics() { return collect(DoubleSummaryStatistics::new, DoubleSummaryStatistics::accept, DoubleSummaryStatistics::combine); }
Spliterator.OfDouble spliterator = spliterator(); double size = spliterator.getExactSizeIfKnown(); DoubleBuffer buf = new DoubleBuffer(size >= 0 && size <= Integer.MAX_VALUE ? (int) size : INITIAL_SIZE); delegate(spliterator).forEachOrdered(i -> buf.add(buf.size == 0 ? i : accumulator.applyAsDouble(buf.data[buf.size - 1], i))); return buf.toArray();
/** * Returns a {@code float[]} array containing the elements of this stream * which are converted to floats using {@code (float)} cast operation. * * <p> * This is a terminal operation. * * @return an array containing the elements of this stream * @since 0.3.0 */ public float[] toFloatArray() { if (isParallel()) return collect(DoubleCollector.toFloatArray()); java.util.Spliterator.OfDouble spliterator = spliterator(); long size = spliterator.getExactSizeIfKnown(); FloatBuffer buf; if (size >= 0 && size <= Integer.MAX_VALUE) { buf = new FloatBuffer((int) size); spliterator.forEachRemaining((DoubleConsumer) buf::addUnsafe); } else { buf = new FloatBuffer(); spliterator.forEachRemaining((DoubleConsumer) buf::add); } return buf.toArray(); }
/** * Returns a stream consisting of the elements of this stream that strictly * greater than the specified value. * * <p> * This is an intermediate operation. * * @param value a value to compare to * @return the new stream * @since 0.2.3 */ public DoubleStreamEx greater(double value) { return filter(val -> val > value); }
/** * Returns an {@link OptionalLong} describing the zero-based index of the * first element of this stream, which matches given predicate, or an empty * {@code OptionalLong} if there's no matching element. * * <p> * This is a short-circuiting terminal operation. * * @param predicate a * <a href="package-summary.html#NonInterference">non-interfering * </a>, <a href="package-summary.html#Statelessness">stateless</a> * predicate which returned value should match * @return an {@code OptionalLong} describing the index of the first * matching element of this stream, or an empty {@code OptionalLong} * if there's no matching element. * @see #findFirst(DoublePredicate) * @since 0.4.0 */ public OptionalLong indexOf(DoublePredicate predicate) { return boxed().indexOf(predicate::test); }
/** * Returns a stream where the first element is the replaced with the result * of applying the given function while the other elements are left intact. * * <p> * This is a <a href="package-summary.html#StreamOps">quasi-intermediate * operation</a>. * * @param mapper a * <a href="package-summary.html#NonInterference">non-interfering * </a>, <a href="package-summary.html#Statelessness">stateless</a> * function to apply to the first element * @return the new stream * @since 0.4.1 */ public DoubleStreamEx mapFirst(DoubleUnaryOperator mapper) { return delegate(new PairSpliterator.PSOfDouble((a, b) -> b, mapper, spliterator(), PairSpliterator.MODE_MAP_FIRST)); }
private static DoubleStreamEx seq(DoubleStream stream) { return new DoubleStreamEx(stream, StreamContext.SEQUENTIAL); }
/** * Returns a {@link String} which is the concatenation of the results of * calling {@link String#valueOf(double)} on each element of this stream, * separated by the specified delimiter, in encounter order. * * <p> * This is a terminal operation. * * @param delimiter the delimiter to be used between each element * @return the result of concatenation. For empty input stream empty String * is returned. * @since 0.3.1 */ public String joining(CharSequence delimiter) { return collect(DoubleCollector.joining(delimiter)); }
/** * Returns a stream consisting of the elements of this stream that greater * than or equal to the specified value. * * <p> * This is an intermediate operation. * * @param value a value to compare to * @return the new stream * @since 0.2.3 */ public DoubleStreamEx atLeast(double value) { return filter(val -> val >= value); }