Interface FilteringOperators<T>
-
- Type Parameters:
T
- The type of the elements that the stream emits.
- All Known Subinterfaces:
ProcessorBuilder<T,R>
,PublisherBuilder<T>
public interface FilteringOperators<T>
Operations for transforming a stream.The documentation for each operator uses marble diagrams to visualize how the operator functions. Each element flowing in and out of the stream is represented as a coloured marble that has a value, with the operator applying some transformation or some side effect, termination and error signals potentially being passed, and for operators that subscribe to the stream, an output value being redeemed at the end.
Below is an example diagram labelling all the parts of the stream.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description FilteringOperators<T>
distinct()
Creates a stream consisting of the distinct elements (according toObject.equals(Object)
) of this stream.FilteringOperators<T>
dropWhile(java.util.function.Predicate<? super T> predicate)
Drop the longest prefix of elements from this stream that satisfy the givenpredicate
.FilteringOperators<T>
filter(java.util.function.Predicate<? super T> predicate)
Filter elements emitted by this publisher using the givenPredicate
.FilteringOperators<T>
limit(long maxSize)
Truncate this stream, ensuring the stream is no longer thanmaxSize
elements in length.FilteringOperators<T>
skip(long n)
Discard the firstn
of this stream.FilteringOperators<T>
takeWhile(java.util.function.Predicate<? super T> predicate)
Take the longest prefix of elements from this stream that satisfy the givenpredicate
.
-
-
-
Method Detail
-
filter
FilteringOperators<T> filter(java.util.function.Predicate<? super T> predicate)
Filter elements emitted by this publisher using the givenPredicate
.Any elements that return
true
when passed to thePredicate
will be emitted, all other elements will be dropped.- Parameters:
predicate
- The predicate to apply to each element.- Returns:
- A new stream builder.
-
distinct
FilteringOperators<T> distinct()
Creates a stream consisting of the distinct elements (according toObject.equals(Object)
) of this stream.- Returns:
- A new stream builder emitting the distinct elements from this stream.
-
limit
FilteringOperators<T> limit(long maxSize)
Truncate this stream, ensuring the stream is no longer thanmaxSize
elements in length.If
maxSize
is reached, the stream will be completed, and upstream will be cancelled. Completion of the stream will occur immediately when the element that satisfies themaxSize
is received.- Parameters:
maxSize
- The maximum size of the returned stream.- Returns:
- A new stream builder.
- Throws:
java.lang.IllegalArgumentException
- IfmaxSize
is less than zero.
-
skip
FilteringOperators<T> skip(long n)
Discard the firstn
of this stream. If this stream contains fewer thann
elements, this stream will effectively be an empty stream.- Parameters:
n
- The number of elements to discard.- Returns:
- A new stream builder.
- Throws:
java.lang.IllegalArgumentException
- Ifn
is less than zero.
-
takeWhile
FilteringOperators<T> takeWhile(java.util.function.Predicate<? super T> predicate)
Take the longest prefix of elements from this stream that satisfy the givenpredicate
.When the
predicate
returns false, the stream will be completed, and upstream will be cancelled.- Parameters:
predicate
- The predicate.- Returns:
- A new stream builder.
-
dropWhile
FilteringOperators<T> dropWhile(java.util.function.Predicate<? super T> predicate)
Drop the longest prefix of elements from this stream that satisfy the givenpredicate
.As long as the
predicate
returns true, no elements will be emitted from this stream. Once the first element is encountered for which thepredicate
returns false, all subsequent elements will be emitted, and thepredicate
will no longer be invoked.- Parameters:
predicate
- The predicate.- Returns:
- A new stream builder.
-
-