Interface StreamUtils


public interface StreamUtils
Spring Data specific Java Stream utility methods and classes.
Since:
1.10
Author:
Thomas Darimont, Oliver Gierke
  • Method Details

    • createStreamFromIterator

      static <T> Stream<T> createStreamFromIterator(Iterator<T> iterator)
      Returns a Stream backed by the given Iterator
      Parameters:
      iterator - must not be null.
      Returns:
    • createStreamFromIterator

      static <T> Stream<T> createStreamFromIterator(CloseableIterator<T> iterator)
      Returns a Stream backed by the given CloseableIterator and forwarding calls to BaseStream.close() to the iterator.
      Parameters:
      iterator - must not be null.
      Returns:
      Since:
      2.0
    • toUnmodifiableList

      static <T> Collector<T,?,List<T>> toUnmodifiableList()
      Returns a Collector to create an unmodifiable List.
      Returns:
      will never be null.
    • toUnmodifiableSet

      static <T> Collector<T,?,Set<T>> toUnmodifiableSet()
      Returns a Collector to create an unmodifiable Set.
      Returns:
      will never be null.
    • toMultiMap

      static <T, K, V> Collector<T,org.springframework.util.MultiValueMap<K,V>,org.springframework.util.MultiValueMap<K,V>> toMultiMap(Function<T,K> keyFunction, Function<T,V> valueFunction)
      Returns a Collector to create a MultiValueMap.
      Parameters:
      keyFunction - Function to create a key from an element of the Stream
      valueFunction - Function to create a value from an element of the Stream
    • fromNullable

      static <T> Stream<T> fromNullable(@Nullable T source)
      Creates a new Stream for the given value returning an empty Stream if the value is null.
      Parameters:
      source - can be null.
      Returns:
      a new Stream for the given value returning an empty Stream if the value is null.
      Since:
      2.0.6
    • zip

      static <L, R, T> Stream<T> zip(Stream<L> left, Stream<R> right, BiFunction<L,R,T> combiner)
      Zips the given Streams using the given BiFunction. The resulting Stream will have the length of the shorter of the two, abbreviating the zipping when the shorter of the two Streams is exhausted.
      Parameters:
      left - must not be null.
      right - must not be null.
      combiner - must not be null.
      Returns:
      Since:
      2.1