Package com.google.common.collect
Class MoreCollectors
java.lang.Object
com.google.common.collect.MoreCollectors
Collectors not present in
java.util.stream.Collectors that are not otherwise associated
with a com.google.common type.- Since:
- 21.0
- Author:
- Louis Wasserman
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Collector<T,?, T> A collector that takes a stream containing exactly one element and returns that element.A collector that converts a stream of zero or one elements to anOptional.
-
Method Details
-
toOptional
A collector that converts a stream of zero or one elements to anOptional. The returned collector throws anIllegalArgumentExceptionif the stream consists of two or more elements, and aNullPointerExceptionif the stream consists of exactly one element, which is null. -
onlyElement
A collector that takes a stream containing exactly one element and returns that element. The returned collector throws anIllegalArgumentExceptionif the stream consists of two or more elements, and aNoSuchElementExceptionif the stream is empty.
-