1 /*
2 * $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/TestTypeValidator.java,v 1.6 2004/02/21 17:10:30 rleland Exp $
3 * $Revision: 1.6 $
4 * $Date: 2004/02/21 17:10:30 $
5 *
6 * ====================================================================
7 * Copyright 2001-2004 The Apache Software Foundation
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22 package org.apache.commons.validator;
23
24 import org.apache.commons.validator.util.ValidatorUtils;
25
26 /***
27 * Contains validation methods for different unit tests.
28 */
29 public class TestTypeValidator {
30
31 /***
32 * Checks if the field can be successfully converted to a <code>byte</code>.
33 *
34 * @param value The value validation is being performed on.
35 * @return boolean If the field can be successfully converted
36 * to a <code>byte</code> <code>true</code> is returned.
37 * Otherwise <code>false</code>.
38 */
39 public static Byte validateByte(Object bean, Field field) {
40 String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
41
42 return GenericTypeValidator.formatByte(value);
43 }
44
45 /***
46 * Checks if the field can be successfully converted to a <code>short</code>.
47 *
48 * @param value The value validation is being performed on.
49 * @return boolean If the field can be successfully converted
50 * to a <code>short</code> <code>true</code> is returned.
51 * Otherwise <code>false</code>.
52 */
53 public static Short validateShort(Object bean, Field field) {
54 String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
55
56 return GenericTypeValidator.formatShort(value);
57 }
58
59 /***
60 * Checks if the field can be successfully converted to a <code>int</code>.
61 *
62 * @param value The value validation is being performed on.
63 * @return boolean If the field can be successfully converted
64 * to a <code>int</code> <code>true</code> is returned.
65 * Otherwise <code>false</code>.
66 */
67 public static Integer validateInt(Object bean, Field field) {
68 String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
69
70 return GenericTypeValidator.formatInt(value);
71 }
72
73 /***
74 * Checks if the field can be successfully converted to a <code>long</code>.
75 *
76 * @param value The value validation is being performed on.
77 * @return boolean If the field can be successfully converted
78 * to a <code>long</code> <code>true</code> is returned.
79 * Otherwise <code>false</code>.
80 */
81 public static Long validateLong(Object bean, Field field) {
82 String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
83
84 return GenericTypeValidator.formatLong(value);
85 }
86
87 /***
88 * Checks if the field can be successfully converted to a <code>float</code>.
89 *
90 * @param value The value validation is being performed on.
91 * @return boolean If the field can be successfully converted
92 * to a <code>float</code> <code>true</code> is returned.
93 * Otherwise <code>false</code>.
94 */
95 public static Float validateFloat(Object bean, Field field) {
96 String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
97
98 return GenericTypeValidator.formatFloat(value);
99 }
100
101 /***
102 * Checks if the field can be successfully converted to a <code>double</code>.
103 *
104 * @param value The value validation is being performed on.
105 * @return boolean If the field can be successfully converted
106 * to a <code>double</code> <code>true</code> is returned.
107 * Otherwise <code>false</code>.
108 */
109 public static Double validateDouble(Object bean, Field field) {
110 String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
111
112 return GenericTypeValidator.formatDouble(value);
113 }
114
115 }
This page was automatically generated by Maven