Class Reproduce<T>


  • public final class Reproduce<T>
    extends java.lang.Object
    A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value.

    Additional methods that depend on the presence or absence of a contained value are provided, such as (return a default value if value not present) and (execute a block of code if the value is present).

    This is a value-based class; use of identity-sensitive operations (including reference equality (==), identity hash code, or synchronization) on instances of Optional may have unpredictable results and should be avoided.

    Since:
    1.8
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <X extends java.lang.Throwable>
      T
      noException()
      A method does not throw exception.
      <X extends java.lang.Throwable>
      T
      orElseThrow​(java.util.function.Supplier<? extends X> exceptionSupplier)
      Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.
      <X extends java.lang.Throwable>
      T
      orElseThrow2​(java.util.function.Supplier<? extends X> exceptionSupplier)
      Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • noException

        public <X extends java.lang.Throwable> T noException()
        A method does not throw exception.
        Type Parameters:
        X - Type of the exception to be thrown
        Returns:
        the present value exceptionSupplier is null
      • orElseThrow

        public <X extends java.lang.Throwable> T orElseThrow​(java.util.function.Supplier<? extends X> exceptionSupplier)
                                                      throws X extends java.lang.Throwable
        Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.
        Type Parameters:
        X - Type of the exception to be thrown
        Parameters:
        exceptionSupplier - The supplier which will return the exception to be thrown
        Returns:
        the present value
        Throws:
        X - if there is no value present
        java.lang.NullPointerException - if no value is present and exceptionSupplier is null
        X extends java.lang.Throwable
      • orElseThrow2

        public <X extends java.lang.Throwable> T orElseThrow2​(java.util.function.Supplier<? extends X> exceptionSupplier)
                                                       throws X extends java.lang.Throwable,
                                                              java.io.IOException
        Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.
        Type Parameters:
        X - Type of the exception to be thrown
        Parameters:
        exceptionSupplier - The supplier which will return the exception to be thrown
        Returns:
        the present value
        Throws:
        X - if there is no value present
        java.lang.NullPointerException - if no value is present and exceptionSupplier is null
        java.io.IOException - Test case for multiple throws
        X extends java.lang.Throwable