Class DelayedInputRequest<T>

java.lang.Object
nl.pim16aap2.animatedarchitecture.core.util.delayedinput.DelayedInputRequest<T>
Type Parameters:
T - The type of data to request.
Direct Known Subclasses:
DelayedCommandInputRequest, DelayedStructureSpecificationInputRequest

public class DelayedInputRequest<T> extends Object
Represents a request for delayed input. E.g. by waiting for user input.
  • Constructor Details

    • DelayedInputRequest

      protected DelayedInputRequest(long timeout, TimeUnit timeUnit)
      Instantiates a new DelayedInputRequest.
      Parameters:
      timeout - The timeout to wait before giving up. Must be larger than 0.
      timeUnit - The unit of time.
    • DelayedInputRequest

      protected DelayedInputRequest(Duration timeout)
      Instantiates a new DelayedInputRequest.
      Parameters:
      timeout - The amount of time to wait before cancelling the request.
  • Method Details

    • cancel

      public final void cancel()
      Cancels the request if it is still waiting for input.

      Calling this method after the request has already completed has no effect.

      See completed().

    • set

      public final void set(@Nullable T value)
      Provides the value that this object is waiting for.

      Calling this method after the request has already completed has no effect.

      See completed().

      Parameters:
      value - The new value.
    • cleanup

      protected void cleanup()
      Runs after the request has closed. Either because input was provided or because the request timed out.

      See getStatus().

    • cancelled

      public boolean cancelled()
      Checks if the input request was cancelled.
      Returns:
      True if the input request was cancelled.
    • completed

      public boolean completed()
      Checks if the input request was completed. This includes via timing out / cancellation / exception / success.
      Returns:
      True if the input request was completed.
    • timedOut

      public boolean timedOut()
      Check if the request timed out while waiting for input.
      Returns:
      True if the request timed out.
    • exceptionally

      public boolean exceptionally()
      Checks if the request was completed with an exception.
      Returns:
      True if the request was completed with an exception.
    • success

      public boolean success()
      Checks if the request was fulfilled successfully.
      Returns:
      True if the request was completed successfully.
    • getStatus

      public DelayedInputRequest.Status getStatus()
      Gets the current status of this request.
      Returns:
      The current status of this request.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getInputResult

      protected CompletableFuture<Optional<T>> getInputResult()
      The result of this input request.