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