Package com.google.common.collect
Class MoreCollectors
- java.lang.Object
-
- com.google.common.collect.MoreCollectors
-
@GwtCompatible public final class MoreCollectors extends java.lang.Object
Collectors not present injava.util.stream.Collectorsthat are not otherwise associated with acom.google.commontype.- Since:
- 21.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classMoreCollectors.ToOptionalStateThis 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 Modifier and Type Field Description private static java.lang.ObjectNULL_PLACEHOLDERprivate static java.util.stream.Collector<java.lang.Object,?,java.lang.Object>ONLY_ELEMENTprivate static java.util.stream.Collector<java.lang.Object,?,java.util.Optional<java.lang.Object>>TO_OPTIONAL
-
Constructor Summary
Constructors Modifier Constructor Description privateMoreCollectors()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.stream.Collector<T,?,T>onlyElement()A collector that takes a stream containing exactly one element and returns that element.static <T> java.util.stream.Collector<T,?,java.util.Optional<T>>toOptional()A collector that converts a stream of zero or one elements to anOptional.
-
-
-
Field Detail
-
TO_OPTIONAL
private static final java.util.stream.Collector<java.lang.Object,?,java.util.Optional<java.lang.Object>> TO_OPTIONAL
-
NULL_PLACEHOLDER
private static final java.lang.Object NULL_PLACEHOLDER
-
ONLY_ELEMENT
private static final java.util.stream.Collector<java.lang.Object,?,java.lang.Object> ONLY_ELEMENT
-
-
Method Detail
-
toOptional
public static <T> java.util.stream.Collector<T,?,java.util.Optional<T>> 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
public static <T> java.util.stream.Collector<T,?,T> 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.
-
-