Class Validation.Builder

java.lang.Object
io.keikai.axyra.sheets.content.Validation.Builder
Enclosing class:
Validation

public static final class Validation.Builder extends Object
A fluent builder for a Validation. Tokens are checked only when the rule is applied with Range.setValidation, and an unknown token is replaced, not rejected.

 Validation rule = Validation.builder()
         .type("decimal").operator("greaterThan").formula1("0")
         .errorMessage("Invalid amount", "Enter a positive number.")
         .build();
 
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • type

      public Validation.Builder type(String type)
      Sets the validation type: whole, decimal, list, date, time, textLength or custom. An unknown token is not rejected; the rule then allows any value.
    • operator

      public Validation.Builder operator(String operator)
      Sets the comparison: between, notBetween, equal, notEqual, greaterThan, lessThan, greaterThanOrEqual or lessThanOrEqual. An unknown or missing token is read as between. Ignored by list and custom rules.
    • formula1

      public Validation.Builder formula1(String f)
      Sets the first operand: a formula without a leading =, such as "10", "$A$1", "DATE(2020,1,1)" or, for a list, "\"A,B\"" or "$X$1:$X$9". The text is saved as is, so a leading = is kept and date text such as "2020-01-01" is read as arithmetic.
    • formula2

      public Validation.Builder formula2(String f)
      Sets the second operand, used only by between and notBetween; same form as formula1(String).
    • allowBlank

      public Validation.Builder allowBlank(boolean b)
      Sets whether a blank cell passes the rule; true by default.
    • showDropdown

      public Validation.Builder showDropdown(boolean b)
      Whether a list rule shows its in-cell drop-down arrow; shown when not set. Ignored for other types.
    • errorMessage

      public Validation.Builder errorMessage(String title, String message)
      Sets the error alert's title and text and turns the alert on.
    • errorStyle

      public Validation.Builder errorStyle(String style)
      Sets the alert style: stop (rejects the entry; the default), warning or information. An unknown token is read as stop.
    • showErrorMessage

      public Validation.Builder showErrorMessage(boolean b)
      Whether a failure raises a message at all.

      Separate from errorMessage(String, String), which implies it: a rule can validate silently, and there is no other way to say so.

    • showInputMessage

      public Validation.Builder showInputMessage(boolean b)
      Whether the input hint is shown when the cell is selected.
    • inputMessage

      public Validation.Builder inputMessage(String title, String message)
      Sets the input hint's title and text and turns the hint on.
    • build

      public Validation build()
      The immutable rule. Tokens are checked only when the rule is applied with Range.setValidation.