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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classThis atrocity is here to let us report several of the elements in the stream if there were more than one, not just two. -
Field Summary
Fields -
Constructor Summary
Constructors -
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.
-
Field Details
-
TO_OPTIONAL
-
NULL_PLACEHOLDER
-
ONLY_ELEMENT
-
-
Constructor Details
-
MoreCollectors
private MoreCollectors()
-
-
Method Details
-
toOptional
A collector that converts a stream of zero or one elements to anOptional.- Returns:
Optional.of(onlyElement)if the stream has exactly one element (must not benull) and returnsOptional.empty()if it has none.- Throws:
IllegalArgumentException- if the stream consists of two or more elements.NullPointerException- if any element in the stream isnull.
-
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.
-