Class CommandValidator.ValidationResult

java.lang.Object
com.ultikits.ultitools.abstracts.command.validation.CommandValidator.ValidationResult
Enclosing interface:
CommandValidator

public static final class CommandValidator.ValidationResult extends Object
Result of a validation operation.
Since:
6.2.0
Version:
2.0.0
Author:
wisdomme
  • Field Details

    • valid

      private final boolean valid
    • errorMessage

      private final String errorMessage
    • errorKey

      private final String errorKey
    • errorText

      private final Text errorText
  • Constructor Details

    • ValidationResult

      private ValidationResult(boolean valid, @Nullable String errorMessage, @Nullable String errorKey)
    • ValidationResult

      private ValidationResult(boolean valid, @Nullable String errorMessage, @Nullable String errorKey, @Nullable Text errorText)
  • Method Details

    • failure

      public static CommandValidator.ValidationResult failure(Text message, String errorKey)
      Creates a failure rendered in the eventual recipient's language.
      Parameters:
      message - deferred error text
      errorKey - diagnostic key, retained independently of the text
      Returns:
      a failure whose getErrorMessage() is null
      Since:
      7.0.0
    • getErrorText

      @Nullable public Text getErrorText()
      Returns deferred text, or null for success and legacy string failures.
      Returns:
      deferred error text
      Since:
      7.0.0
    • success

      public static CommandValidator.ValidationResult success()
      Creates a successful validation result.
      Returns:
      a success result
    • failure

      public static CommandValidator.ValidationResult failure(String errorMessage)
      Creates a failed validation result with a message.
      Parameters:
      errorMessage - the error message
      Returns:
      a failure result
    • failure

      public static CommandValidator.ValidationResult failure(String errorMessage, String errorKey)
      Creates a failed validation result with a message and i18n key.
      Parameters:
      errorMessage - the error message
      errorKey - the i18n key for the error
      Returns:
      a failure result
    • isValid

      public boolean isValid()
      Checks if the validation was successful.
      Returns:
      true if valid
    • getErrorMessage

      @Nullable public String getErrorMessage()
      Gets the error message if validation failed.
      Returns:
      the legacy string, or null if valid or constructed with deferred Text
    • getErrorKey

      @Nullable public String getErrorKey()
      Gets the i18n key for the error message.
      Returns:
      the error key, or null if not set