@API(status=INTERNAL,
since="1.0")
public final class CollectionUtils
extends java.lang.Object
Collections
.
These utilities are intended solely for usage within the JUnit framework itself. Any usage by external parties is not supported. Use at your own risk!
Modifier | Constructor and Description |
---|---|
private |
CollectionUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
getOnlyElement(java.util.Collection<T> collection)
Read the only element of a collection of size 1.
|
static <T> java.util.Set<T> |
toSet(T[] values)
Convert the supplied array of values to a
Set . |
static java.util.stream.Stream<?> |
toStream(java.lang.Object object)
Convert an object of one of the following supported types into a
Stream . |
static <T> java.util.stream.Collector<T,?,java.util.List<T>> |
toUnmodifiableList()
Return a
Collector that accumulates the input elements into a
new unmodifiable list, in encounter order. |
public static <T> T getOnlyElement(java.util.Collection<T> collection)
collection
- the collection to get the element fromPreconditionViolationException
- if the collection is null
or does not contain exactly one element@API(status=INTERNAL, since="1.6") public static <T> java.util.Set<T> toSet(T[] values)
Set
.values
- the array of values; never null
PreconditionViolationException
- if the array is null
public static <T> java.util.stream.Collector<T,?,java.util.List<T>> toUnmodifiableList()
Collector
that accumulates the input elements into a
new unmodifiable list, in encounter order.
There are no guarantees on the type or serializability of the list
returned, so if more control over the returned list is required,
consider creating a new Collector
implementation like the
following:
public static <T> Collector<T, ?, List<T>> toUnmodifiableList(Supplier<List<T>> listSupplier) { return Collectors.collectingAndThen(Collectors.toCollection(listSupplier), Collections::unmodifiableList); }
T
- the type of the input elementsCollector
which collects all the input elements into
an unmodifiable list, in encounter orderpublic static java.util.stream.Stream<?> toStream(java.lang.Object object)
Stream
.
Stream
DoubleStream
IntStream
LongStream
Collection
Iterable
Iterator
Object
arrayobject
- the object to convert into a stream; never null
PreconditionViolationException
- if the supplied object is null
or not one of the supported types