Package net.hironico.common.utils
Class StreamUtils
java.lang.Object
net.hironico.common.utils.StreamUtils
JAVA 8+ happy developpers can use these super usefull streams utils to get their life easier.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Collector<T,?, T> This collector assumes there is one and only one element in the stream and collect it.static <T> Stream<T>stream(Enumeration<T> enumeration) Convert an Enumeration into Stream using Spliteratorstatic <T> TuncheckCall(Callable<T> callable) Unckec any checked exception that could be thrown in a stream call.
-
Constructor Details
-
StreamUtils
public StreamUtils()
-
-
Method Details
-
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 theStream.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
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
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
-