01: package org.jreform.criteria;
02:
03: import java.util.Arrays;
04:
05: /**
06: * Checks that value is equal to one of the acceptable values.
07: *
08: * @author armandino (at) gmail.com
09: */
10: public class Accept<T> extends AbstractCriterion<T> {
11: private T[] acceptableValues;
12:
13: Accept(T... values) {
14: this .acceptableValues = values;
15: }
16:
17: protected final boolean verify(T value) {
18: for (T v : acceptableValues) {
19: if (areEqual(v, value))
20: return true;
21: }
22:
23: return false;
24: }
25:
26: protected boolean areEqual(T v1, T v2) {
27: return v1.equals(v2);
28: }
29:
30: protected String generateErrorMessage() {
31: return "Please enter one of the allowed values "
32: + Arrays.asList(acceptableValues);
33: }
34:
35: }
|