Class StreamUtils

java.lang.Object
net.hironico.common.utils.StreamUtils

public class StreamUtils extends Object
JAVA 8+ happy developpers can use these super usefull streams utils to get their life easier.
  • Constructor Details

    • StreamUtils

      public StreamUtils()
  • Method Details

    • singletonCollector

      public static <T> Collector<T,?,T> singletonCollector()
      This collector assumes there is one and only one element in the stream and collect it. If there is more than one element in the stream then illegal state exception is thrown. If the stream is empty then returns null. Use the returned collector as a parameter in the Stream.collect(Collector) Source : https://stackoverflow.com/questions/22694884/filter-java-stream-to-1-and-only-1-element/50514439
      Type Parameters:
      T - the single element class in this stream
      Returns:
      the instance of the single element in the stream.
    • uncheckCall

      public static <T> T uncheckCall(Callable<T> callable)
      Unckec any checked exception that could be thrown in a stream call. See https://stackoverflow.com/questions/19757300/java-8-lambda-streams-filter-by-method-with-exception DO NOT USE WITHOUT ALERTING EVERY SINGLE PROGRAMMER IN THE POJECT OF THIS CODE !
      Type Parameters:
      T -
      Parameters:
      callable -
      Returns:
    • stream

      public static <T> Stream<T> stream(Enumeration<T> enumeration)
      Convert an Enumeration into Stream using Spliterator
      Type Parameters:
      T - the type of the enumeration elements
      Parameters:
      enumeration - to convert into Stream
      Returns:
      a Stream containing the enumeration's elements of type T