Class CheckedValue<T,​E extends Exception>

    • Constructor Detail

      • CheckedValue

        protected CheckedValue​(T value)
      • CheckedValue

        protected CheckedValue​(E violation,
                               @Nullable Void dummy)
    • Method Detail

      • ofException

        public static <T,​E extends ExceptionCheckedValue<T,​E> ofException​(E cause)
        Create a new instance containing an Exception.
        Type Parameters:
        T - Value type
        E - Exception type
        Parameters:
        cause - Throwable
        Returns:
        A new instance
        Throws:
        NullPointerException - if cause is null
      • ofValue

        public static <T,​E extends ExceptionCheckedValue<T,​E> ofValue​(T value)
        Create a new instance containing specified value.
        Type Parameters:
        T - Value type
        E - Exception type
        Parameters:
        value - Value
        Returns:
        A new instance
        Throws:
        NullPointerException - if value is null
      • ofVariant

        public static <T,​U,​E extends ExceptionCheckedValue<T,​E> ofVariant​(Variant<T,​U> variant,
                                                                                              Function<U,​E> mapper)
        Convert a Variant into a CheckedValue, converting the second value into an exception.
        Type Parameters:
        T - First alternative type
        U - Second alternative type
        E - Exception type
        Parameters:
        variant - Input variant
        mapper - Mapping function from second alternative to an exception
        Returns:
        Resulting CheckedValue
      • getException

        public final E getException()
        Return the contained error string if isPresent() would return false, throws IllegalStateException otherwise.
        Returns:
        Throwable which was used to instantiate this object, or absent if it was instantiated using an error string.
        Throws:
        IllegalStateException - if a value is present.
      • isPresent

        public final boolean isPresent()
        Return true if a value is present.
        Returns:
        True if a value is present.
      • ifPresent

        public final void ifPresent​(Consumer<? super T> consumer)
        If a value is present, invoke the specified consumer with the value, otherwise do nothing.
        Parameters:
        consumer - block to be executed if a value is present
        Throws:
        NullPointerException - if value is present and consumer is null
      • orElse

        public final T orElse​(T other)
        Return contained value if present, otherwise return supplied value.
        Parameters:
        other - Replacement value
        Returns:
        Contained value or {code other}
      • orElseGet

        public final T orElseGet​(Supplier<T> supplier)
        Return contained value if present, otherwise return the value produced by a supplier.
        Parameters:
        supplier - Replacement value supplier
        Returns:
        Contained value or supplier's value
        Throws:
        NullPointerException - if supplier is null
      • orElseThrow

        public final T orElseThrow()
                            throws E extends Exception
        Return contained value if present or throw the exception alternative.
        Returns:
        Contained value
        Throws:
        E - When there is no contained value
        E extends Exception
      • orElseThrow

        public final <X extends ThrowableT orElseThrow​(Function<E,​X> exceptionMapper)
                                                  throws X extends Throwable
        Return contained value if present or throw the exception alternative mapped through provided mapper.
        Type Parameters:
        X - Thrown exception type
        Parameters:
        exceptionMapper - Exception mapper
        Returns:
        Contained value
        Throws:
        NullPointerException - if exceptionMapper is null
        X - When there is no contained value
        X extends Throwable
      • orElseThrow

        public final <X extends ThrowableT orElseThrow​(Supplier<X> supplier)
                                                  throws X extends Throwable
        Return contained value if present or throw the exception supplied by supplier.
        Type Parameters:
        X - Thrown exception type
        Parameters:
        supplier - Exception supplier
        Returns:
        Contained value
        Throws:
        NullPointerException - if exceptionMapper is null
        X - When there is no contained value
        X extends Throwable
      • completeFuture

        public final boolean completeFuture​(CompletableFuture<T> future)
        Complete target CompletableFuture either successfully or exceptionally based on the state of this object.
        Parameters:
        future - Future to complete
        Returns:
        True if this call has transitioned the future to a completed state, false otherwise.
        Throws:
        NullPointerException - if {code future} is null
      • completeFuture

        public final boolean completeFuture​(SettableFuture<T> future)
        Complete target SettableFuture either successfully or exceptionally based on the state of this object.
        Parameters:
        future - Future to complete
        Returns:
        True if this call has transitioned the future to a completed state, false otherwise.
        Throws:
        NullPointerException - if {code future} is null
      • toCompletableFuture

        public final CompletableFuture<T> toCompletableFuture()
        Transform this object into an immediately-completed CompletableFuture. The future will be successful if this object has a contained value or unsuccessful if this objects contains an exception.
        Returns:
        A CompletableFuture.
      • toFluentFuture

        public final FluentFuture<T> toFluentFuture()
        Transform this object into an immediately-completed FluentFuture. The future will be successful if this object has a contained value or unsuccessful if this objects contains an exception.
        Returns:
        A FluentFuture.