Package it.tidalwave.bluemarine2.rest
Class RestResponse<T>
- java.lang.Object
-
- it.tidalwave.bluemarine2.rest.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 multipleOptional
s.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()
Returnstrue
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.
-
-
-
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()
Returnstrue
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 multipleOptional
s.- 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
-
-