Interface SpectateResponse<SI extends SpectatorInventory<?>>
- Type Parameters:
SI
- the type of SpectatorInventory
public interface SpectateResponse<SI extends SpectatorInventory<?>>
A SpectateResponse can either be successful, or not.
If a SpectateResponse is successful,
isSuccess()
returns true and getInventory()
returns a SpectatorInventory
normally.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <SI extends SpectatorInventory<?>>
SpectateResponse<SI> fail
(NotCreatedReason reason) Create a failed SpectateResponse.static <SI extends SpectatorInventory<?>>
SpectateResponse<SI> fromOptional
(Optional<SI> optional) Convert anOptional
into a SpectateResponse.static <SI extends SpectatorInventory<?>>
SpectateResponse<SI> fromOptional
(Optional<SI> optional, NotCreatedReason ifEmpty) Convert anOptional
into a SpectateResponse.Get the SpectatorInventory of this response.Get the reason why the spectator inventory could not be created.default void
ifFailure
(Consumer<? super NotCreatedReason> reasonConsumer) Much likeOptional.ifPresent(Consumer)
default void
Much likeOptional.ifPresent(Consumer)
boolean
Get whether this response was successful.static <SI extends SpectatorInventory<?>>
SpectateResponse<SI> succeed
(SI spectatorInventory) Create a succeeded SpectateResponse.static <SI extends SpectatorInventory<?>>
Optional<SI> toOptional
(SpectateResponse<SI> response) Convert a SpectateResponse into anOptional
.
-
Method Details
-
isSuccess
boolean isSuccess()Get whether this response was successful.- Returns:
- true if this response is successful, otherwise false
-
getInventory
Get the SpectatorInventory of this response.- Returns:
- the spectator inventory
- Throws:
NoSuchElementException
- if this response is not successful
-
getReason
Get the reason why the spectator inventory could not be created.- Returns:
- the reason
- Throws:
NoSuchElementException
- if this response is successful
-
ifSuccess
Much likeOptional.ifPresent(Consumer)
-
ifFailure
Much likeOptional.ifPresent(Consumer)
-
succeed
Create a succeeded SpectateResponse.- Parameters:
spectatorInventory
- the spectator inventory to succeed with- Returns:
- a new SpectateResponse
-
fail
Create a failed SpectateResponse.- Parameters:
reason
- the reason why it failed- Returns:
- a new SpectateResponse
-
fromOptional
static <SI extends SpectatorInventory<?>> SpectateResponse<SI> fromOptional(Optional<SI> optional, NotCreatedReason ifEmpty) Convert anOptional
into a SpectateResponse.- Parameters:
optional
- the optional value used for successifEmpty
- the reason used to fail the SpectateReponse if the optional Optional.isEmpty()- Returns:
- a new SpectateResponse
-
fromOptional
Convert anOptional
into a SpectateResponse. -
toOptional
Convert a SpectateResponse into anOptional
. The optional will have a value present if the spectate response is successful. If the spectate response is not successful, then the returned optional will be empty.- Parameters:
response
- the SpectateResponse- Returns:
- the optional
-