public final class ObjectStreams
extends java.lang.Object
Utility methods for streams.
Modifier and Type | Method and Description |
---|---|
static <T> ObjectStream<T> |
concat(java.lang.Iterable<? extends ObjectStream<? extends T>> streams)
Concatenate object streams.
|
static <T> ObjectStream<T> |
concat(ObjectStream<? extends T>... objectStreams)
Concatenate object streams.
|
static <T> ObjectStream<T> |
consume(int n,
ObjectStream<T> stream)
Consume and discard the first
n elements from an object stream. |
static int |
count(ObjectStream<?> objectStream)
Deprecated.
Use
Stream.collect(Collector) . |
static <T> ObjectStream<T> |
empty()
Create an empty object stream.
|
static <T> ObjectStream<T> |
filter(ObjectStream<?> source,
java.lang.Class<T> type)
Filter an object stream to only contain elements of type type.
|
static <T> ObjectStream<T> |
filter(ObjectStream<T> stream,
Predicate<? super T> predicate)
Filter an object stream.
|
static <T> java.util.List<T> |
makeList(ObjectStream<? extends T> objectStream)
Deprecated.
Use
Stream.collect(Collector) . |
static <T> ObjectStream<T> |
of(T... contents)
Create an object stream over a fixed set of elements.
|
static <T> ObjectStream<T> |
sort(ObjectStream<T> objectStream,
java.util.Comparator<? super T> comp)
Deprecated.
Use
Stream.sorted(Comparator) , possibly with wrap(Stream, Closeable) . |
static <S,T> ObjectStream<T> |
transform(ObjectStream<S> objectStream,
Function<? super S,? extends T> function)
Deprecated.
Use
Stream.map(java.util.function.Function) , possibly with wrap(Stream, Closeable) . |
static <T> ObjectStream<T> |
wrap(java.util.Collection<? extends T> collection)
Wrap a collection in an object stream.
|
static <T> ObjectStream<T> |
wrap(java.util.Iterator<? extends T> iterator)
Wrap an iterator in an object stream.
|
static <T> ObjectStream<T> |
wrap(java.util.stream.Stream<? extends T> stream)
Wrap a Java stream in an object stream.
|
static <T> ObjectStream<T> |
wrap(java.util.stream.Stream<? extends T> stream,
java.io.Closeable root)
Wrap a Java stream in an object stream.
|
public static <T> ObjectStream<T> wrap(java.util.Iterator<? extends T> iterator)
Wrap an iterator in an object stream.
The iterator may not contain null
. This property is checked lazily; the object stream will not fail until the null
would be returned.
T
- The type of data to return.iterator
- An iterator to wrappublic static <T> ObjectStream<T> wrap(java.util.stream.Stream<? extends T> stream)
Wrap a Java stream in an object stream.
The stream may not contain null
. This property is checked lazily; the object stream will not fail until the null
would be returned.
T
- The type of data to return.stream
- A stream to wrappublic static <T> ObjectStream<T> wrap(java.util.stream.Stream<? extends T> stream, @WillCloseWhenClosed java.io.Closeable root)
Wrap a Java stream in an object stream.
The stream may not contain null
. This property is checked lazily; the object stream will not fail until the null
would be returned.
T
- The type of data to return.stream
- A stream to wraproot
- The ‘root stream’, which will be closed when the resulting stream is closed.public static <T> ObjectStream<T> wrap(java.util.Collection<? extends T> collection)
Wrap a collection in an object stream.
The iterator may not contain null
. This property is checked lazily; the object stream will not fail until the null
would be returned.
T
- The type of data to return.collection
- A collection to wrappublic static <T> ObjectStream<T> filter(@WillCloseWhenClosed ObjectStream<T> stream, Predicate<? super T> predicate)
Filter an object stream.
T
- The type of object stream rows.stream
- The source stream.predicate
- A predicate indicating which rows to return.true
.public static <T> ObjectStream<T> filter(@WillCloseWhenClosed ObjectStream<?> source, java.lang.Class<T> type)
Filter an object stream to only contain elements of type type. Unlike filter(ObjectStream, Predicate)
with a predicate from Predicates.instanceOf(Class)
, this method also transforms the stream to be of the target type.
T
- The type of value in the stream.source
- The source stream.type
- The type to filter.public static <T> ObjectStream<T> consume(int n, ObjectStream<T> stream)
Consume and discard the first n
elements from an object stream.
n
- The number of elements to drop.stream
- The stream.T
- The stream’s element type.stream
is modified.@Deprecated public static <S,T> ObjectStream<T> transform(@WillCloseWhenClosed ObjectStream<S> objectStream, Function<? super S,? extends T> function)
Stream.map(java.util.function.Function)
, possibly with wrap(Stream, Closeable)
.Transform an object stream’s values.
S
- The type of source stream rowsT
- The type of output stream rowsobjectStream
- The source streamfunction
- A function to apply to each row in the stream. It will be applied to each value at most once.public static <T> ObjectStream<T> empty()
Create an empty object stream.
T
- The type of value in the object stream.@Deprecated public static <T> java.util.List<T> makeList(@WillClose ObjectStream<? extends T> objectStream)
Stream.collect(Collector)
.Read an object stream into a list, closing when it is finished.
T
- The type of item in the object stream.objectStream
- The object stream.@Deprecated public static int count(@WillClose ObjectStream<?> objectStream)
Stream.collect(Collector)
.Count the items in a stream.
objectStream
- The object stream.@Deprecated public static <T> ObjectStream<T> sort(@WillClose ObjectStream<T> objectStream, java.util.Comparator<? super T> comp)
Stream.sorted(Comparator)
, possibly with wrap(Stream, Closeable)
.Sort an object stream. This reads the original object stream into a list, sorts it, and returns a new object stream backed by the list (after closing the original object stream).
T
- The type of value in the object stream.objectStream
- The object stream to sort.comp
- The comparator to use to sort the object stream.@SafeVarargs public static <T> ObjectStream<T> of(T... contents)
Create an object stream over a fixed set of elements. This is mostly useful for testing.
contents
- The contents.T
- The data type.public static <T> ObjectStream<T> concat(java.lang.Iterable<? extends ObjectStream<? extends T>> streams)
Concatenate object streams. Each object stream is closed as closed as it is consumed.
streams
- The object streams to concatenate.T
- The type of data.@SafeVarargs public static <T> ObjectStream<T> concat(ObjectStream<? extends T>... objectStreams)
Concatenate object streams.
concat(Iterable)