T - The type of the contained object.public interface AtMostOne<T>
throw an exception if there are elements that will be discarded
if assuming that there is at most one element present.| Modifier and Type | Interface and Description |
|---|---|
static class |
AtMostOne.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(Collection<T> list) |
static <T> AtMostOne<T> |
from(Iterable<T> iterable) |
static <T> AtMostOne<T> |
from(Stream<T> stream) |
default Optional<T> |
get()
Get the at most single contained element, or throw a
AtMostOne.TooManyElements exception
if there are excessive elements available. |
<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> discardRemaining()
Stream.findFirst().Optional.empty() if no elements exist.default Optional<T> get()
AtMostOne.TooManyElements exception
if there are excessive elements available. If you need controll over the thrown exception, use
orIfExcessiveThrow(Supplier)Optional.empty() if no elements exist.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. The stream
passed to this function will always contain at least
two elements (the expected first element, and the excess ones).Optional.empty() if no elements exist.X - if the function to handle more than one elements throws an exception.X extends Throwablestatic <T> AtMostOne<T> from(Collection<T> list)
Copyright © 2016 Digipost. All rights reserved.