1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.validatedattrib.constraint.primitive;
18
19 import net.sf.validatedattrib.ValidationException;
20
21 /**
22 * TODO: document me
23 *
24 * @author Philip May
25 */
26 public class ValidatedDoubleMinMaxConstraint implements DoubleConstraint {
27
28 private double min;
29 private double max;
30
31 public ValidatedDoubleMinMaxConstraint(double min, double max) {
32 this.min = min;
33 this.max = max;
34 }
35
36 /**
37 * TODO: write JavaDoc
38 *
39 * @throws ValidationException
40 * @see net.sf.validatedattrib.constraint.Constraint#validate(java.lang.Object)
41 */
42 public void validate(Object newValue) throws ValidationException {
43 Double d = (Double) newValue;
44 if (d.doubleValue() > max) {
45 throw new ValidationException(">" + max + "!");
46 }
47 if (d.doubleValue() < min) {
48 throw new ValidationException("<" + min + "!");
49 }
50 }
51
52 }