Class Rules<T>

java.lang.Object
com.jsgalactic.axiom.validation.Rules<T>
Type Parameters:
T - type of value checked
All Implemented Interfaces:
BodyValidator<T>, Validator<T>

public final class Rules<T> extends Object implements Validator<T>
An immutable, annotation-free validator built from field rules.

 import static com.jsgalactic.axiom.validation.Rule.*;

 static final Validator<CreateUser> CREATE_USER = Rules.of(CreateUser.class)
         .field("name", CreateUser::name, notBlank(), maxLength(80))
         .field("email", CreateUser::email, notNull(), email())
         .field("age", CreateUser::age, range(0, 150))
         .nested("address", CreateUser::address, ADDRESS)
         .eachNested("items", CreateUser::items, ITEM)
         .check("end", user -> !user.end().isBefore(user.start()), "before_start");
 

Every method returns a new instance, so partially built rule sets can be shared and extended; instances are thread-safe as long as the supplied accessors, predicates and validators are. Steps run in declaration order. Each field reports at most the first rule it fails. Nested validators and collection elements extend field paths, for example items[2].name, and null nested objects, lists and list elements are skipped by nested, each and eachNested, so presence is stated with Rule.notNull(). Validation stops once Validation.MAX_VIOLATIONS violations are collected. Field names and codes are checked when the rules are defined. Exceptions thrown by accessors, predicates or nested validators propagate unchanged.