Class StreamUtils

java.lang.Object
io.micronaut.core.util.StreamUtils

public class StreamUtils extends Object
Utility methods for working with streams.
Since:
1.0
Author:
James Kleeh
  • Constructor Details

    • StreamUtils

      public StreamUtils()
  • Method Details

    • maxAll

      public static <T, A, D> Collector<T,?,D> maxAll(Comparator<? super T> comparator, Collector<? super T,A,D> downstream)
      A collector that returns all results that are the maximum based on the provided comparator.
      Type Parameters:
      T - The type of objects being streamed
      A - The mutable accumulation type of the reduction operation
      D - The result type of the reduction operation
      Parameters:
      comparator - The comparator to order the items in the stream
      downstream - Which collector to use to combine the results
      Returns:
      A new collector to provide the desired result
    • minAll

      public static <T, A, D> Collector<T,?,D> minAll(Comparator<? super T> comparator, Collector<? super T,A,D> downstream)
      A collector that returns all results that are the minimum based on the provided comparator.
      Type Parameters:
      T - The type of objects being streamed
      A - The mutable accumulation type of the reduction operation
      D - The result type of the reduction operation
      Parameters:
      comparator - The comparator to order the items in the stream
      downstream - Which collector to use to combine the results
      Returns:
      A new collector to provide the desired result
    • toImmutableCollection

      public static <T, A extends Collection<T>> Collector<T,A,Collection<T>> toImmutableCollection(Supplier<A> collectionFactory)
      Type Parameters:
      T - The type of the input elements
      A - The accumulation type
      Parameters:
      collectionFactory - The collection factory
      Returns:
      An immutable collection