コード例 #1
0
 @Override
 public void addRule(final Rule rule) {
   if (rules.contains(rule)) {
     return;
   }
   if (rule.isImportant()) {
     rules.add(0, rule);
   } else {
     rules.add(rule);
   }
 }
コード例 #2
0
 /** Runs validation against our rules. */
 private void validate() {
   valid = Valid.YES; // start out valid
   for (final Rule rule : rules) {
     if (rule.validate() == Valid.YES) {
       rule.untriggerIfNeeded();
     } else {
       // only trigger the first invalid rule
       if (valid == Valid.YES) {
         if (isTouched()) {
           rule.triggerIfNeeded();
         } else {
           rule.untriggerIfNeeded();
         }
         valid = Valid.NO;
       } else {
         rule.untriggerIfNeeded();
       }
     }
   }
 }