@Beta
@NonNullByDefault
@ThreadSafe
-public final class CheckedValue<T, E extends Exception> extends Variant<T, E> {
- private CheckedValue(final T value) {
+public class CheckedValue<T, E extends Exception> extends Variant<T, E> {
+ protected CheckedValue(final T value) {
super(value);
}
- private CheckedValue(final E violation, final @Nullable Void dummy) {
+ protected CheckedValue(final E violation, final @Nullable Void dummy) {
super(violation, dummy);
}
* @return Contained value
* @throws IllegalStateException if an error string is present.
*/
- public T get() {
+ public final T get() {
if (isFirst()) {
return first();
}
* string.
* @throws IllegalStateException if a value is present.
*/
- public E getException() {
+ public final E getException() {
if (isSecond()) {
return second();
}
*
* @return True if a value is present.
*/
- public boolean isPresent() {
+ public final boolean isPresent() {
return isFirst();
}
* @param consumer block to be executed if a value is present
* @throws NullPointerException if value is present and {@code consumer} is null
*/
- public void ifPresent(final Consumer<? super T> consumer) {
+ public final void ifPresent(final Consumer<? super T> consumer) {
if (isFirst()) {
consumer.accept(first());
}
* @param other Replacement value
* @return Contained value or {code other}
*/
- public T orElse(final T other) {
+ public final T orElse(final T other) {
return isFirst() ? first() : other;
}
* @return Contained value or supplier's value
* @throws NullPointerException if {@code supplier} is null
*/
- public T orElseGet(final Supplier<T> supplier) {
+ public final T orElseGet(final Supplier<T> supplier) {
requireNonNull(supplier);
return isFirst() ? first() : supplier.get();
}
* @return Contained value
* @throws E When there is no contained value
*/
- public <X extends Throwable> T orElseThrow() throws E {
+ public final <X extends Throwable> T orElseThrow() throws E {
if (isFirst()) {
return first();
}
* @throws NullPointerException if {@code exceptionMapper} is null
* @throws X When there is no contained value
*/
- public <X extends Throwable> T orElseThrow(final Function<E, X> exceptionMapper) throws X {
+ public final <X extends Throwable> T orElseThrow(final Function<E, X> exceptionMapper) throws X {
requireNonNull(exceptionMapper);
if (isFirst()) {
return first();
* @throws NullPointerException if {@code exceptionMapper} is null
* @throws X When there is no contained value
*/
- public <X extends Throwable> T orElseThrow(final Supplier<X> supplier) throws X {
+ public final <X extends Throwable> T orElseThrow(final Supplier<X> supplier) throws X {
requireNonNull(supplier);
if (isFirst()) {
return first();
* @return True if this call has transitioned the future to a completed state, false otherwise.
* @throws NullPointerException if {code future} is null
*/
- public boolean completeFuture(final CompletableFuture<T> future) {
+ public final boolean completeFuture(final CompletableFuture<T> future) {
return isFirst() ? future.complete(first()) : future.completeExceptionally(second());
}
* @return True if this call has transitioned the future to a completed state, false otherwise.
* @throws NullPointerException if {code future} is null
*/
- public boolean completeFuture(final SettableFuture<T> future) {
+ public final boolean completeFuture(final SettableFuture<T> future) {
return isFirst() ? future.set(first()) : future.setException(second());
}
*
* @return A {@link CompletableFuture}.
*/
- public CompletableFuture<T> toCompletableFuture() {
+ public final CompletableFuture<T> toCompletableFuture() {
if (isFirst()) {
return CompletableFuture.completedFuture(first());
}
*
* @return A {@link FluentFuture}.
*/
- public FluentFuture<T> toFluentFuture() {
+ public final FluentFuture<T> toFluentFuture() {
final ListenableFuture<T> future;
if (isFirst()) {
future = Futures.immediateFuture(first());