01: package dinamica;
02:
03: import java.util.Date;
04:
05: /**
06: * Utility class to validate String values against data types
07: * in order to test if the value represents de data type (dates, numbers, etc.)
08: * <br>
09: * Creation date: 25/10/2003<br>
10: * Last Update: 25/10/2003<br>
11: * (c) 2003 Martin Cordova<br>
12: * This code is released under the LGPL license<br>
13: * @author Martin Cordova
14: */
15: public class ValidatorUtil {
16:
17: /**
18: * Test a String value to check if it does represent
19: * a valid date according to a specific format
20: * @param dateValue Value to test
21: * @param dateFormat Date format used to represent a date in value
22: * @return NULL if value can't be converted
23: */
24: public static Date testDate(String dateValue, String dateFormat) {
25:
26: try {
27: Date d = StringUtil.getDateObject(dateValue, dateFormat);
28: return d;
29: } catch (Throwable e) {
30: return null;
31: }
32:
33: }
34:
35: /**
36: * Test a String value to check if it does represent
37: * a valid double number
38: * @param doubleValue Value to test
39: * @return NULL if value can't be converted
40: */
41: public static Double testDouble(String doubleValue) {
42:
43: try {
44: double d = Double.parseDouble(doubleValue);
45: return new Double(d);
46: } catch (Throwable e) {
47: return null;
48: }
49:
50: }
51:
52: /**
53: * Test a String value to check if it does represent
54: * a valid integer number
55: * @param integerValue Value to test
56: * @return NULL if value can't be converted
57: */
58: public static Integer testInteger(String integerValue) {
59:
60: try {
61: int i = Integer.parseInt(integerValue);
62: return new Integer(i);
63: } catch (Throwable e) {
64: return null;
65: }
66:
67: }
68:
69: }
|