View Javadoc

1   /*
2    * Copyright 2006 Philip May.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }