01: package org.jreform.criteria;
02:
03: import org.jreform.Criterion;
04:
05: /**
06: * Performs an <tt>AND</tt> over all criteria on the given value.
07: *
08: * @author armandino (at) gmail.com
09: */
10: public final class And<T> extends AbstractCriterion<T> {
11: private Criterion<T>[] criteria;
12: private Criterion<T> failedCriterion;
13:
14: And(Criterion<T>... criteria) {
15: if (criteria.length < 2)
16: throw new IllegalArgumentException(getClass().getName()
17: + " requires at least two criteria");
18:
19: this .criteria = criteria;
20: }
21:
22: protected boolean verify(T value) {
23: for (Criterion<T> criterion : criteria) {
24: if (!criterion.isSatisfied(value)) {
25: failedCriterion = criterion;
26: return false;
27: }
28: }
29:
30: return true;
31: }
32:
33: protected String generateErrorMessage() {
34: return failedCriterion.getOnError();
35: }
36:
37: }
|