Package generic
Interface Unique
public interface Unique
Some utilities for when singleton collections are expected
-
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic <T> TassertAtMostOne(Iterable<T> col) Assert that at most one element is in an iterable and get that element ornullstatic <T> TassertAtMostOne(T[] arr) static <T> TAssert that exactly one element is in an iterable and get that elementstatic <T> TAssert that exactly one element is in a stream and get that element
-
Method Details
-
assertAtMostOne
static <T> T assertAtMostOne(T[] arr) -
assertOne
Assert that exactly one element is in an iterable and get that element- Type Parameters:
T- the type of element- Parameters:
col- the iterable- Returns:
- the element
- Throws:
AssertionError- if no element or many elements exist in the iterable
-
assertOne
Assert that exactly one element is in a stream and get that element- Type Parameters:
T- the type of element- Parameters:
st- the stream- Returns:
- the element
- Throws:
AssertionError- if no element or many elements exist in the stream
-
assertAtMostOne
Assert that at most one element is in an iterable and get that element ornull- Type Parameters:
T- the type of element- Parameters:
col- the iterable- Returns:
- the element or
nullif empty - Throws:
AssertionError- if many elements exist in the iterable
-