Package com.google.common.collect
Class MoreCollectors
- java.lang.Object
-
- com.google.common.collect.MoreCollectors
-
public final class MoreCollectors extends java.lang.Object
Collectors not present injava.util.stream.Collectors
that are not otherwise associated with acom.google.common
type.- Since:
- 21.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
MoreCollectors.ToOptionalState
This 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.Object
NULL_PLACEHOLDER
private static java.util.stream.Collector<java.lang.Object,?,java.lang.Object>
ONLY_ELEMENT
private static java.util.stream.Collector<java.lang.Object,?,java.util.Optional<java.lang.Object>>
TO_OPTIONAL
-
Constructor Summary
Constructors Modifier Constructor Description private
MoreCollectors()
-
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 anIllegalArgumentException
if the stream consists of two or more elements, and aNullPointerException
if 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 anIllegalArgumentException
if the stream consists of two or more elements, and aNoSuchElementException
if the stream is empty.
-
-