Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 1051:8f836fb6f592
Introduced an epsilon (750ms) to be more tolerant while comparing two data objects (issue286).
gnv-artifacts/trunk@1125 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 25 May 2010 17:46:28 +0000 |
parents | f94a95009423 |
children | 46cc1ab1ee15 |
comparison
equal
deleted
inserted
replaced
1050:7f3154331bc1 | 1051:8f836fb6f592 |
---|---|
25 public class InputValidator { | 25 public class InputValidator { |
26 /** | 26 /** |
27 * the logger, used to log exceptions and additonaly information | 27 * the logger, used to log exceptions and additonaly information |
28 */ | 28 */ |
29 private static Logger log = Logger.getLogger(InputValidator.class); | 29 private static Logger log = Logger.getLogger(InputValidator.class); |
30 | |
31 /** | |
32 * Epsilon for handling unprecise date objects (in ms). | |
33 */ | |
34 public final static long DATE_EPSILON = 750; | |
30 | 35 |
31 | 36 |
32 public final static String NODATASELECTEDVALUE = "n/n"; | 37 public final static String NODATASELECTEDVALUE = "n/n"; |
33 | 38 |
34 /** | 39 /** |
219 * @param lo The lower range bound. | 224 * @param lo The lower range bound. |
220 * @param up The upper range bound. | 225 * @param up The upper range bound. |
221 * @return true, if tmp is valid, otherwise false. | 226 * @return true, if tmp is valid, otherwise false. |
222 */ | 227 */ |
223 public static boolean isDateValid(Date tmp, Date lo, Date up) { | 228 public static boolean isDateValid(Date tmp, Date lo, Date up) { |
224 // we need to transform the given dates into seconds, because | 229 long tmpTime = tmp.getTime(); |
225 // they differ in milliseconds -> that's why we cannot use the | 230 long tmpLow = lo.getTime(); |
226 // Date.compareTo(Date) method. | 231 long tmpUp = up.getTime(); |
227 long tmpTime = tmp.getTime() / 1000; | 232 |
228 long tmpLow = lo.getTime() / 1000; | 233 if (tmpTime < tmpLow - DATE_EPSILON || tmpTime > tmpUp + DATE_EPSILON) { |
229 long tmpUp = up.getTime() / 1000; | |
230 | |
231 if (tmpTime < tmpLow || tmpTime > tmpUp) { | |
232 log.warn( | 234 log.warn( |
233 "Date [" + tmp.toString() + "] is out of range [" | 235 "Date [" + tmp.toString() + "] is out of range [" |
234 + lo.toString() + " to "+ up.toString() + "]."); | 236 + lo.toString() + " to "+ up.toString() + "]."); |
235 return false; | 237 return false; |
236 } | 238 } |