T - The type of the contained object.public interface AtMostOne<T> extends ViewableAsOptional<T>
throw an exception if there are elements that will be discarded
if assuming that there is at most one element present.
If this funcitonality is needed for streams, use the using DiggCollectors.allowAtMostOne()
collector instead with Stream.collect(..).
ViewableAsOptional.Single<V>, ViewableAsOptional.TooManyElements| Modifier and Type | Method and Description |
|---|---|
default Optional<T> |
discardRemaining()
This allows to just pick out the first element, and basically offers the same functionality
as
Stream.findFirst(). |
static <T> AtMostOne<T> |
from(Iterable<T> iterable) |
<X extends Throwable> |
orElse(ThrowingRunnable<X> handleUnexpectedMultipleElements)
How to handle if there actually are multiple elements available when only at most one is expected.
|
default <X extends Throwable> |
orIfExcessiveThrow(Supplier<X> exceptionSupplier)
Pick out the single contained element, or throw the given exception if there are
excessive (more than one) elements available.
|
default Optional<T> |
toOptional()
Get the at most single contained element, or throw a
TooManyElements exception
if there are excessive elements available. |
default Optional<T> discardRemaining()
Stream.findFirst().Optional.empty() if no elements exist.default Optional<T> toOptional()
TooManyElements exception
if there are excessive elements available. If you need control over the thrown exception, use
orIfExcessiveThrow(Supplier).toOptional in interface ViewableAsOptional<T>Optional.empty() if no elements exist or
the single element is null.default <X extends Throwable> Optional<T> orIfExcessiveThrow(Supplier<X> exceptionSupplier) throws X extends Throwable
exceptionSupplier - the exception to throw if there are excessive elements available.Optional.empty() if no elements exist.X - if there are excessive elements available.X extends Throwable<X extends Throwable> Optional<T> orElse(ThrowingRunnable<X> handleUnexpectedMultipleElements) throws X extends Throwable
handleUnexpectedMultipleElements - the handling of the unexpected multiple elements.Optional.empty() if no elements exist.X - if the function to handle more than one elements throws an exception.X extends ThrowableCopyright © 2018 Digipost. All rights reserved.