MaxRowsValidator.java
package server.restful.common.validator;
import com.beust.jcommander.IParameterValidator;
import com.beust.jcommander.ParameterException;
public class MaxRowsValidator implements IParameterValidator {
private static final int MAX_ROWS = 500;
@Override
public void validate(String name, String value) throws ParameterException {
try {
int n = Integer.parseInt(value);
if (n < 0 || n > MAX_ROWS) {
throw new ParameterException(
"Invalid " + name + " value, expected 0.." + MAX_ROWS + " (found " + value + ")");
}
} catch (NumberFormatException e) {
throw new ParameterException("Parameter " + name + " should be an int (found " + value + ")");
}
}
}