Class RestResponse<T>


  • public class RestResponse<T>
    extends java.lang.Object
    Author:
    Fabrizio Giudici
    • Constructor Summary

      Constructors 
      Constructor Description
      RestResponse()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <X> RestResponse<X> empty()  
      <U> java.util.Optional<U> flatMap​(java.util.function.Function<? super T,​java.util.Optional<U>> mapper)
      Maps the result, if present, to a new value using a mapping function, avoiding wrapping with multiple Optionals.
      T get()
      Returns the datum, if available.
      void ifPresent​(java.util.function.Consumer<? super T> consumer)
      If a value is present, invoke the specified consumer with the value, otherwise do nothing.
      boolean isPresent()
      Returns true if the datum is available.
      <U> java.util.Optional<U> map​(java.util.function.Function<? super T,​? extends U> mapper)
      Maps the result, if present, to a new value using a mapping function.
      • Methods inherited from class java.lang.Object

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

      • RestResponse

        public RestResponse()
    • Method Detail

      • empty

        @Nonnull
        public static <X> RestResponse<X> empty()
      • get

        @Nonnull
        public T get()
              throws java.util.NoSuchElementException
        Returns the datum, if available.
        Returns:
        the datum
        Throws:
        java.util.NoSuchElementException - if the datum is not available
      • isPresent

        public boolean isPresent()
        Returns true if the datum is available.
        Returns:
        true if the datum is available
      • map

        @Nonnull
        public <U> java.util.Optional<U> map​(@Nonnull
                                             java.util.function.Function<? super T,​? extends U> mapper)
        Maps the result, if present, to a new value using a mapping function.
        Type Parameters:
        U - the type of the result
        Parameters:
        mapper - a mapping function to apply to the value, if present
        Returns:
        an Optional result
      • flatMap

        @Nonnull
        public <U> java.util.Optional<U> flatMap​(@Nonnull
                                                 java.util.function.Function<? super T,​java.util.Optional<U>> mapper)
        Maps the result, if present, to a new value using a mapping function, avoiding wrapping with multiple Optionals.
        Type Parameters:
        U - the type of the result
        Parameters:
        mapper - a mapping function to apply to the value, if present
        Returns:
        an Optional result
      • ifPresent

        public void ifPresent​(@Nonnull
                              java.util.function.Consumer<? super T> consumer)
        If a value is present, invoke the specified consumer with the value, otherwise do nothing.
        Parameters:
        consumer - code to be executed if a value is present