Class ValidationResult<T>

java.lang.Object
net.ixdarklord.coolcatcore.api.config.type.ValidationResult<T>

public final class ValidationResult<T> extends Object
The outcome of checking a value: fine as is, corrected into a valid value (a number clamped into its range, say), or rejected.

A file holding a correctable value loads the corrected one and is rewritten; the config screen and commands only accept values that are fine as they are.

  • Method Details

    • ok

      public static <T> ValidationResult<T> ok(T value)
    • corrected

      public static <T> ValidationResult<T> corrected(T corrected, net.minecraft.network.chat.Component message)
      The value was invalid; corrected is the closest valid one and message says what was wrong.
    • error

      public static <T> ValidationResult<T> error(net.minecraft.network.chat.Component message)
    • isOk

      public boolean isOk()
    • isCorrected

      public boolean isCorrected()
    • isError

      public boolean isError()
    • hasValue

      public boolean hasValue()
      Whether there's a usable value: fine or corrected.
    • value

      public T value()
      The value, or the corrected value.
      Throws:
      IllegalStateException - for an error
    • message

      public Optional<net.minecraft.network.chat.Component> message()
      What was wrong; empty when the value is fine.
    • messageString

      public String messageString()
    • map

      public <R> ValidationResult<R> map(Function<? super T,? extends R> mapper)
      Maps a usable value; a correction or an error carries over.
    • then

      public ValidationResult<T> then(Function<? super T,ValidationResult<T>> next)
      Runs another check on the usable value. An earlier correction survives a later check that passes; the first error wins.
    • toString

      public String toString()
      Overrides:
      toString in class Object