Class StreamUtils


  • public class StreamUtils
    extends java.lang.Object
    Utility methods for working with streams.
    Since:
    1.0
    • Constructor Summary

      Constructors 
      Constructor Description
      StreamUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T,​A,​D>
      java.util.stream.Collector<T,​?,​D>
      maxAll​(java.util.Comparator<? super T> comparator, java.util.stream.Collector<? super T,​A,​D> downstream)
      A collector that returns all results that are the maximum based on the provided comparator.
      static <T,​A,​D>
      java.util.stream.Collector<T,​?,​D>
      minAll​(java.util.Comparator<? super T> comparator, java.util.stream.Collector<? super T,​A,​D> downstream)
      A collector that returns all results that are the minimum based on the provided comparator.
      static <T> java.util.stream.Collector<T,​java.util.Collection<T>,​java.util.Collection<T>> toImmutableCollection()  
      static <T,​A extends java.util.Collection<T>>
      java.util.stream.Collector<T,​A,​java.util.Collection<T>>
      toImmutableCollection​(java.util.function.Supplier<A> collectionFactory)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StreamUtils

        public StreamUtils()
    • Method Detail

      • maxAll

        public static <T,​A,​D> java.util.stream.Collector<T,​?,​D> maxAll​(java.util.Comparator<? super T> comparator,
                                                                                               java.util.stream.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> java.util.stream.Collector<T,​?,​D> minAll​(java.util.Comparator<? super T> comparator,
                                                                                               java.util.stream.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 java.util.Collection<T>> java.util.stream.Collector<T,​A,​java.util.Collection<T>> toImmutableCollection​(java.util.function.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
      • toImmutableCollection

        public static <T> java.util.stream.Collector<T,​java.util.Collection<T>,​java.util.Collection<T>> toImmutableCollection()
        Type Parameters:
        T - The type
        Returns:
        An immutable collection