@Override public boolean noneMatch(Predicate<? super T> predicate) { return !anyMatch(predicate); }
/** * Returns an {@link Optional} describing the first element of this stream, * which matches given predicate, or an empty {@code Optional} 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 Optional} describing the first matching element of this * stream, or an empty {@code Optional} if there's no matching * element * @throws NullPointerException if the element selected is null * @see #findFirst() */ public Optional<T> findFirst(Predicate<? super T> predicate) { return filter(predicate).findFirst(); }
/** * Returns an {@link Optional} describing some element of the stream, which * matches given predicate, or an empty {@code Optional} 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(Predicate)} 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 Optional} describing some matching element of this * stream, or an empty {@code Optional} if there's no matching * element * @throws NullPointerException if the element selected is null * @see #findAny() * @see #findFirst(Predicate) */ public Optional<T> findAny(Predicate<? super T> predicate) { return filter(predicate).findAny(); }
return distinct(); Spliterator<T> spliterator = spliterator(); Spliterator<T> result; if (spliterator.hasCharacteristics(Spliterator.DISTINCT)) else result = new DistinctSpliterator<>(spliterator, atLeast); return supply(result);
/** * Returns a stream consisting of the elements of this stream that aren't * null. * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate * operation</a>. * * @return the new stream */ public S nonNull() { return filter(Objects::nonNull); }
/** * Returns a stream consisting of the results of replacing each element of * this stream with the contents of a mapped collection produced by applying * the provided mapping function to each element. (If a mapped collection is * {@code null} nothing is added for given element to the resulting stream.) * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate * operation</a>. * * <p> * The {@code flatCollection()} operation has the effect of applying a * one-to-many transformation to the elements of the stream, and then * flattening the resulting elements into a new stream. * * @param <R> The element type of the new stream * @param mapper a <a * href="package-summary.html#NonInterference">non-interfering </a>, * <a href="package-summary.html#Statelessness">stateless</a> * function to apply to each element which produces a * {@link Collection} of new values * @return the new stream */ public <R> StreamEx<R> flatCollection(Function<? super T, ? extends Collection<? extends R>> mapper) { return flatMap(t -> { Collection<? extends R> c = mapper.apply(t); return c == null ? null : StreamEx.of(c.spliterator()); }); }
/** * Creates a lazily concatenated stream whose elements are all the elements * of this stream followed by all the elements of the other stream. The * resulting stream is ordered if both of the input streams are ordered, and * parallel if either of the input streams is parallel. When the resulting * stream is closed, the close handlers for both input streams are invoked. * * <p> * This is a <a href="package-summary.html#StreamOps">quasi-intermediate * operation</a> with <a href="package-summary.html#TSO">tail-stream * optimization</a>. * * <p> * May return this if the supplied stream is known to be empty. * * @param other the other stream * @return this stream appended by the other stream * @see Stream#concat(Stream, Stream) */ public S append(Stream<? extends T> other) { return appendSpliterator(other, other.spliterator()); }
return collect(new CancellableCollectorImpl<>(() -> new long[]{-1}, (acc, t) -> { if (acc[0] < 0) { if (predicate.test(t)) {
/** * Returns a stream consisting of the elements of this stream that don't * match the given predicate. * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate * operation</a>. * * @param predicate a <a * href="package-summary.html#NonInterference">non-interfering </a>, * <a href="package-summary.html#Statelessness">stateless</a> * predicate to apply to each element to determine if it should be * excluded * @return the new stream */ public S remove(Predicate<? super T> predicate) { return filter(predicate.negate()); }
/** * Returns a stream consisting of the results of replacing each element of * this stream with the contents of a mapped array produced by applying * the provided mapping function to each element. (If a mapped array is * {@code null} nothing is added for given element to the resulting stream.) * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate * operation</a>. * * <p> * The {@code flatArray()} operation has the effect of applying a * one-to-many transformation to the elements of the stream, and then * flattening the resulting elements into a new stream. * * @param <R> The element type of the new stream * @param mapper a <a * href="package-summary.html#NonInterference">non-interfering </a>, * <a href="package-summary.html#Statelessness">stateless</a> * function to apply to each element which produces an * array of new values * @return the new stream * @since 0.6.5 */ public <R> StreamEx<R> flatArray(Function<? super T, ? extends R[]> mapper) { return flatMap(t -> { R[] a = mapper.apply(t); return a == null ? null : StreamEx.of(Arrays.spliterator(a)); }); }