View Javadoc

1   // Copyright 2006-2007, by the California Institute of Technology.
2   // ALL RIGHTS RESERVED. United States Government Sponsorship acknowledged.
3   // Any commercial use must be negotiated with the Office of Technology Transfer
4   // at the California Institute of Technology.
5   //
6   // This software is subject to U. S. export control laws and regulations
7   // (22 C.F.R. 120-130 and 15 C.F.R. 730-774). To the extent that the software
8   // is subject to U.S. export control laws and regulations, the recipient has
9   // the responsibility to obtain export licenses or other export authority as
10  // may be required before exporting such information to foreign countries or
11  // providing access to foreign nationals.
12  //
13  // $Id: RealChecker.java 2601 2007-04-12 18:34:25Z pramirez $ 
14  //
15  
16  package gov.nasa.pds.tools.dict.type;
17  
18  /***
19   * @author pramirez
20   * @version $Revision: 2601 $
21   * 
22   */
23  public class RealChecker extends LengthChecker implements NumericTypeChecker {
24  
25      /* (non-Javadoc)
26       * @see gov.nasa.jpl.pds.tools.label.validate.TypeChecker#cast(java.lang.String)
27       */
28      public Object cast(String value) throws InvalidTypeException {
29          Double doubleValue = null;
30          try {
31              doubleValue = Double.valueOf(value);
32          } catch(NumberFormatException nfe) {
33              throw new InvalidTypeException(nfe.getMessage());
34          }
35          return doubleValue;
36      }
37  
38      /* (non-Javadoc)
39       * @see gov.nasa.pds.tools.dict.type.NumericTypeChecker#checkMinValue(java.lang.Number, java.lang.Number)
40       */
41      public void checkMinValue(Number value, Number min) throws OutOfRangeException {
42          if (value.longValue() < min.longValue())
43              throw new OutOfRangeException(value.toString() + " is less than the acceptable minimum of " + min.toString());
44      }
45  
46      /* (non-Javadoc)
47       * @see gov.nasa.pds.tools.dict.type.NumericTypeChecker#checkMaxValue(java.lang.Number, java.lang.Number)
48       */
49      public void checkMaxValue(Number value, Number max) throws OutOfRangeException {
50          if (value.longValue() > max.longValue())
51              throw new OutOfRangeException(value.toString() + " exceeds acceptable maximum of " + max.toString());
52      }
53  
54  }