comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 806:2cea76f1112e

Added Javadoc in utils package. gnv-artifacts/trunk@888 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 08 Apr 2010 13:10:39 +0000
parents feae2f9d6c6f
children 05bf8534a35a
comparison
equal deleted inserted replaced
805:bb7afd783321 806:2cea76f1112e
36 */ 36 */
37 public InputValidator() { 37 public InputValidator() {
38 super(); 38 super();
39 } 39 }
40 40
41 /**
42 * Validates the input of a range of double or date values. The input values
43 * need to be valid double or date values. <i>minInput</i> needs to be
44 * smaller or equal <i>maxInput</i>.
45 *
46 * @param minInput The lower bound.
47 * @param maxInput The upper bound.
48 * @param type One of 'Date' or 'Double'.
49 * @return true, if the input is valid, otherwise false.
50 */
41 public static boolean isInputValid(String minInput, String maxInput, String type) { 51 public static boolean isInputValid(String minInput, String maxInput, String type) {
42 log.debug("InputValidator.isInputValid " + minInput + " " + maxInput + " " +type); 52 log.debug("InputValidator.isInputValid " + minInput + " " + maxInput + " " +type);
43 boolean returnValue = false; 53 boolean returnValue = false;
44 if ("Date".equalsIgnoreCase(type)) { 54 if ("Date".equalsIgnoreCase(type)) {
45 try { 55 try {
61 } 71 }
62 log.debug("Is valid? " + returnValue); 72 log.debug("Is valid? " + returnValue);
63 return returnValue; 73 return returnValue;
64 } 74 }
65 75
76 /**
77 * Validates an input.
78 *
79 * @param input The input value.
80 * @param type The input value type.
81 * @return true if the input is valid, otherwise false.
82 */
66 public static boolean isInputValid(String input, String type) { 83 public static boolean isInputValid(String input, String type) {
67 log.debug("InputValidator.isInputValid " + input + " " + type); 84 log.debug("InputValidator.isInputValid " + input + " " + type);
68 85
69 // Let's check polygons and linestrings first, because they might 86 // Let's check polygons and linestrings first, because they might
70 // contain comma. A splitting at comma characters wouldn't be good here. 87 // contain comma. A splitting at comma characters wouldn't be good here.
133 log.debug("Is valid? " + returnValue); 150 log.debug("Is valid? " + returnValue);
134 return returnValue; 151 return returnValue;
135 } 152 }
136 153
137 154
155 /**
156 * Returns a point from wkt string.
157 *
158 * @param value The wkt string.
159 * @return a point.
160 * @throws ValidationException if <i>value</i> is not valid.
161 */
138 public static Point getPointValue(String value) throws ValidationException{ 162 public static Point getPointValue(String value) throws ValidationException{
139 log.debug("InputValidator.getPointValue " + value); 163 log.debug("InputValidator.getPointValue " + value);
140 164
141 if (value.toLowerCase().startsWith("point")){ 165 if (value.toLowerCase().startsWith("point")){
142 try { 166 try {
182 return new GeometryFactory().createPoint(new Coordinate(x,y)); 206 return new GeometryFactory().createPoint(new Coordinate(x,y));
183 } 207 }
184 } 208 }
185 209
186 210
211 /**
212 * Makes sure that <i>tmp</i> is between <i>lo</i> and <i>up</i>.
213 *
214 * @param tmp The value to validate.
215 * @param lo The lower range bound.
216 * @param up The upper range bound.
217 * @return true, if tmp is valid, otherwise false.
218 */
187 public static boolean isDateValid(Date tmp, Date lo, Date up) { 219 public static boolean isDateValid(Date tmp, Date lo, Date up) {
188 // we need to transform the given dates into seconds, because 220 // we need to transform the given dates into seconds, because
189 // they differ in milliseconds -> that's why we cannot use the 221 // they differ in milliseconds -> that's why we cannot use the
190 // Date.compareTo(Date) method. 222 // Date.compareTo(Date) method.
191 long tmpTime = tmp.getTime() / 1000; 223 long tmpTime = tmp.getTime() / 1000;
200 } 232 }
201 233
202 return true; 234 return true;
203 } 235 }
204 } 236 }
237 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org