01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.validator;
16:
17: import org.apache.commons.validator.GenericValidator;
18:
19: /**
20: * Validator which ensures that value is within a given range. Uses Commons Validator
21: * <code>GenericValidator.isInRange()</code>. Uses the converted value, so needs tot be used in
22: * conjunction with a <code>Converter</code>
23: * @author Phil Zoio
24: */
25: public class LongRangeValidator extends LongValidator implements
26: Validator<Long> {
27:
28: private long min = Long.MIN_VALUE;
29:
30: private long max = Long.MAX_VALUE;
31:
32: public LongRangeValidator() {
33: super ();
34: }
35:
36: /**
37: * Uses <code>GenericValidator.isInRange()</code> to determine whether value is within given
38: * range. If not required and no value specified, then returns true
39: *
40: */
41: public boolean validate(Long value) {
42:
43: boolean ok = super .validate(value);
44:
45: if (!ok)
46: return false;
47: return GenericValidator.isInRange(value.longValue(), min, max);
48:
49: }
50:
51: /**
52: * Sets the maximum value in range. Defaults to <code>Longs.MAX_VALUE</code>
53: */
54: public void setMax(long max) {
55: this .max = max;
56: }
57:
58: /**
59: * Sets the minimum value in range. Defaults to <code>Long.MIN_VALUE</code>
60: */
61: public void setMin(long min) {
62: this .min = min;
63: }
64:
65: public long getMax() {
66: return max;
67: }
68:
69: public long getMin() {
70: return min;
71: }
72:
73: }
|