Record Class Validation

java.lang.Object
java.lang.Record
org.inspirenxe.strata.api.component.Validation
Record Components:
severity - how serious it is
message - what the user should read, such as "Enter a number from 1 to 64"; empty for VALID

public record Validation(Validation.Severity severity, Text message) extends Record
Whether a control's value is acceptable, and why not, as a Validatable control shows it. An error marks the value as wrong, such as "abc" in a quantity field; a warning marks it as allowed but worth a look, such as a weak password.
box.setValidator(field -> field.text().isBlank() ? Validation.error(Text.of("Enter a name")) : Validation.VALID);
save.bind(Component.ENABLED, check.map(Validation::isValid));
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    How serious a validation is.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Validation
    Nothing to report.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Validation(Validation.Severity severity, Text message)
    Checks the arguments.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    static Validation
    error(Text message)
    Returns an error: the value is wrong.
    final int
    Returns a hash code value for this object.
    boolean
    Returns whether the value may be used, which is anything but an error, so a form can enable its Save button while its fields only warn.
    Returns the value of the message record component.
    Returns the value of the severity record component.
    final String
    Returns a string representation of this record class.
    static Validation
    warning(Text message)
    Returns a warning: the value is allowed but worth a look.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • VALID

      public static final Validation VALID
      Nothing to report.
  • Constructor Details

  • Method Details

    • error

      public static Validation error(Text message)
      Returns an error: the value is wrong.
      Parameters:
      message - why, as the user should read it
      Returns:
      the validation
    • warning

      public static Validation warning(Text message)
      Returns a warning: the value is allowed but worth a look.
      Parameters:
      message - why, as the user should read it
      Returns:
      the validation
    • isValid

      public boolean isValid()
      Returns whether the value may be used, which is anything but an error, so a form can enable its Save button while its fields only warn.
      Returns:
      true unless the severity is Validation.Severity.ERROR
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • severity

      public Validation.Severity severity()
      Returns the value of the severity record component.
      Returns:
      the value of the severity record component
    • message

      public Text message()
      Returns the value of the message record component.
      Returns:
      the value of the message record component