/*
* Copyright 2005-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.strecks.validator;
import org.apache.commons.validator.GenericValidator;
/**
* Validator which ensures that value is within a given range. Uses Commons Validator
* <code>GenericValidator.isInRange()</code>. Uses the converted value, so needs tot be used in
* conjunction with a <code>Converter</code>
* @author Phil Zoio
*/
public class LongRangeValidator extends LongValidator implements Validator<Long>
{
private long min = Long.MIN_VALUE;
private long max = Long.MAX_VALUE;
public LongRangeValidator()
{
super();
}
/**
* Uses <code>GenericValidator.isInRange()</code> to determine whether value is within given
* range. If not required and no value specified, then returns true
*
*/
public boolean validate(Long value)
{
boolean ok = super.validate(value);
if (!ok)
return false;
return GenericValidator.isInRange(value.longValue(), min, max);
}
/**
* Sets the maximum value in range. Defaults to <code>Longs.MAX_VALUE</code>
*/
public void setMax(long max)
{
this.max = max;
}
/**
* Sets the minimum value in range. Defaults to <code>Long.MIN_VALUE</code>
*/
public void setMin(long min)
{
this.min = min;
}
public long getMax()
{
return max;
}
public long getMin()
{
return min;
}
}
|