Class SessionCreationResult

java.lang.Object
com.ohacd.matchbox.api.SessionCreationResult

public final class SessionCreationResult extends Object
Result object for session creation operations that provides detailed success/failure information.

This class enhances error reporting compared to simple Optional returns, allowing developers to understand exactly why a session creation failed.

Example usage:


 SessionCreationResult result = MatchboxAPI.createSessionBuilder("arena1")
     .withPlayers(players)
     .withSpawnPoints(spawns)
     .startWithResult();
 
 if (result.isSuccess()) {
     ApiGameSession session = result.getSession();
     // Use session
 } else {
     SessionCreationResult.ErrorType error = result.getErrorType();
     String message = result.getErrorMessage();
     logger.warning("Failed to create session: " + error + " - " + message);
 }
 
Since:
0.9.5
  • Method Details

    • success

      @NotNull public static @NotNull SessionCreationResult success(@NotNull @NotNull ApiGameSession session)
      Creates a successful result.
      Parameters:
      session - the created session
      Returns:
      a successful result
    • failure

      @NotNull public static @NotNull SessionCreationResult failure(@NotNull @NotNull SessionCreationResult.ErrorType errorType, @Nullable @Nullable String errorMessage)
      Creates a failure result.
      Parameters:
      errorType - the type of error that occurred
      errorMessage - detailed error message (can be null for default message)
      Returns:
      a failure result
    • isSuccess

      public boolean isSuccess()
      Gets whether the session creation was successful.
      Returns:
      true if successful, false otherwise
    • isFailure

      public boolean isFailure()
      Gets whether the session creation failed.
      Returns:
      true if failed, false otherwise
    • getSession

      @NotNull public @NotNull Optional<ApiGameSession> getSession()
      Gets the created session if successful.
      Returns:
      Optional containing the session if successful, empty otherwise
    • getErrorType

      @NotNull public @NotNull Optional<SessionCreationResult.ErrorType> getErrorType()
      Gets the error type if the creation failed.
      Returns:
      Optional containing the error type if failed, empty otherwise
    • getErrorMessage

      @NotNull public @NotNull Optional<String> getErrorMessage()
      Gets the error message if the creation failed.
      Returns:
      Optional containing the error message if failed, empty otherwise
    • toOptional

      @Deprecated @NotNull public @NotNull Optional<ApiGameSession> toOptional()
      Deprecated.
      Use getSession() for more detailed information
      Converts this result to the legacy Optional format for backward compatibility.
      Returns:
      Optional containing the session if successful, empty otherwise
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object