PrevTopNext

Developing Rules for Value Checks (1)

Parameters for a range check of an integer field in a fact:
  • the class containing the field,
  • the name of the field,
  • the lower and upper bounds,
  • the error message text.
    class IntRangeCheck extends Check {
      int lower, upper;
      String error;
      IntRangeCheck( Class clazz, String field,
                     int lower, int upper,
                     String error ){
        super( clazz, field );
        ...
      }
    
      boolean isValid( Object object ){
        Object value = field.get( object );
        if( value == null ) return false;
        int intValue = (Integer)value;
        return lower <= intValue && intValue <= upper;
      }
    

PrevTopNext