01: package org.jreform.criteria;
02:
03: /**
04: * Checks that the length of the value is within the given range.
05: *
06: * @author armandino (at) gmail.com
07: */
08: public final class Length extends AbstractCriterion<String> {
09: private int min;
10: private int max;
11:
12: Length(int min, int max) {
13: this .min = min;
14: this .max = max;
15: }
16:
17: protected boolean verify(String value) {
18: return value.length() <= max && value.length() >= min;
19: }
20:
21: protected String generateErrorMessage() {
22: return "The value must be between " + min + " and " + max
23: + " characters long";
24: }
25:
26: }
|