Package generic
Interface Unique
public interface Unique
Some utilities for when singleton collections are expected
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
assertAtMostOne
(Iterable<T> col) Assert that at most one element is in an iterable and get that element ornull
static <T> T
assertAtMostOne
(T[] arr) static <T> T
Assert that exactly one element is in an iterable and get that elementstatic <T> T
Assert 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
null
if empty - Throws:
AssertionError
- if many elements exist in the iterable
-