@API(value=Internal) public final class CollectionUtils extends 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 and Type | Method and Description |
---|---|
static <T> T |
getOnlyElement(Collection<T> collection)
Read the only element of a collection of size 1.
|
static Stream<?> |
toStream(Object object)
Convert an object of one of the following supported types into a
Stream . |
static <T> Collector<T,?,List<T>> |
toUnmodifiableList()
Return a
Collector that accumulates the input elements into a
new unmodifiable list, in encounter order. |
public static <T> T getOnlyElement(Collection<T> collection)
collection
- the collection to get the element fromPreconditionViolationException
- if the collection is null
or does not contain exactly one elementpublic static <T> Collector<T,?,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 Stream<?> toStream(Object object)
Stream
.
object
- the object to convert into a stream; never null
PreconditionViolationException
- if the supplied object is null
or not one of the supported types