Class Result<T,E>

java.lang.Object
com.coachconnect.util.Result<T,E>

public class Result<T,E> extends Object
  • Method Details

    • success

      public static <T, E> Result<T,E> success(T value)
      Creates a successful result with the given value.
      Type Parameters:
      T - The type of the success value
      E - The type of the error value
      Parameters:
      value - The success value
      Returns:
      A successful Result
    • failure

      public static <T, E> Result<T,E> failure(E error)
      Creates a failure result with the given error.
      Type Parameters:
      T - The type of the success value
      E - The type of the error value
      Parameters:
      error - The error value
      Returns:
      A failure Result
    • isSuccess

      public boolean isSuccess()
      Checks if this result is successful.
      Returns:
      true if the result is successful, false otherwise
    • isFailure

      public boolean isFailure()
      Checks if this result is a failure.
      Returns:
      true if the result is a failure, false otherwise
    • getValue

      public T getValue()
      Gets the success value.
      Returns:
      The success value
      Throws:
      IllegalStateException - if the result is a failure
    • getError

      public E getError()
      Gets the error value.
      Returns:
      The error value
      Throws:
      IllegalStateException - if the result is successful
    • map

      public <U> Result<U,E> map(Function<T,U> mapper)
      Maps the success value to a new value.
      Type Parameters:
      U - The type of the new success value
      Parameters:
      mapper - A function to map the success value
      Returns:
      A new Result with the mapped value, or the original failure