public final class DaggerStreams
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T> java.util.function.Function<java.lang.Object,java.util.stream.Stream<T>> |
instancesOf(java.lang.Class<T> to)
Returns a function from
Object to Stream<T>, which returns a stream containing
its input if its input is an instance of T. |
static <T> java.util.function.Function<java.util.Optional<T>,java.util.stream.Stream<T>> |
presentValues()
A function that you can use to extract the present values from a stream of
Optionals. |
static <T> java.util.stream.Stream<T> |
stream(java.lang.Iterable<T> iterable)
Returns a sequential
Stream of the contents of iterable, delegating to Collection.stream() if possible. |
static <T> java.util.stream.Collector<T,?,com.google.common.collect.ImmutableList<T>> |
toImmutableList()
Returns a
Collector that accumulates the input elements into a new ImmutableList, in encounter order. |
static <T,K,V> java.util.stream.Collector<T,?,com.google.common.collect.ImmutableMap<K,V>> |
toImmutableMap(java.util.function.Function<? super T,K> keyMapper,
java.util.function.Function<? super T,V> valueMapper)
Returns a
Collector that accumulates elements into an ImmutableMap whose keys
and values are the result of applying the provided mapping functions to the input elements. |
static <T> java.util.stream.Collector<T,?,com.google.common.collect.ImmutableSet<T>> |
toImmutableSet()
Returns a
Collector that accumulates the input elements into a new ImmutableSet, in encounter order. |
static <T,K,V> java.util.stream.Collector<T,?,com.google.common.collect.ImmutableSetMultimap<K,V>> |
toImmutableSetMultimap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends V> valueMapper)
Returns a
Collector that accumulates elements into an ImmutableSetMultimap
whose keys and values are the result of applying the provided mapping functions to the input
elements. |
static <E extends java.lang.Enum<E>> |
valuesOf(java.lang.Class<E> enumType)
Returns a stream of all values of the given
enumType. |
public static <T> java.util.stream.Collector<T,?,com.google.common.collect.ImmutableList<T>> toImmutableList()
Collector that accumulates the input elements into a new ImmutableList, in encounter order.public static <T> java.util.stream.Collector<T,?,com.google.common.collect.ImmutableSet<T>> toImmutableSet()
Collector that accumulates the input elements into a new ImmutableSet, in encounter order.public static <T,K,V> java.util.stream.Collector<T,?,com.google.common.collect.ImmutableMap<K,V>> toImmutableMap(java.util.function.Function<? super T,K> keyMapper,
java.util.function.Function<? super T,V> valueMapper)
Collector that accumulates elements into an ImmutableMap whose keys
and values are the result of applying the provided mapping functions to the input elements.
Entries appear in the result ImmutableMap in encounter order.public static <T,K,V> java.util.stream.Collector<T,?,com.google.common.collect.ImmutableSetMultimap<K,V>> toImmutableSetMultimap(java.util.function.Function<? super T,? extends K> keyMapper,
java.util.function.Function<? super T,? extends V> valueMapper)
Collector that accumulates elements into an ImmutableSetMultimap
whose keys and values are the result of applying the provided mapping functions to the input
elements. Entries appear in the result ImmutableSetMultimap in encounter order.public static <T> java.util.function.Function<java.lang.Object,java.util.stream.Stream<T>> instancesOf(java.lang.Class<T> to)
Object to Stream<T>, which returns a stream containing
its input if its input is an instance of T.
Use as an argument to Stream.flatMap(Function):
Stream<Bar> barStream = fooStream.flatMap(instancesOf(Bar.class));public static <E extends java.lang.Enum<E>> java.util.stream.Stream<E> valuesOf(java.lang.Class<E> enumType)
enumType.public static <T> java.util.function.Function<java.util.Optional<T>,java.util.stream.Stream<T>> presentValues()
Optionals.
Set<Foo> foos =
optionalFoos()
.flatMap(DaggerStreams.presentValues())
.collect(toSet());
public static <T> java.util.stream.Stream<T> stream(java.lang.Iterable<T> iterable)
Stream of the contents of iterable, delegating to Collection.stream() if possible.