26 lines
642 B
Java
26 lines
642 B
Java
package org.gcube.accounting.datamodel.validators;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import org.gcube.accounting.exception.InvalidValueException;
|
|
|
|
|
|
public class ValidIntegerValidator implements FieldValidator {
|
|
|
|
private static final String ERROR = String.format("Not Instance of %s", Integer.class.getSimpleName());
|
|
|
|
@Override
|
|
public Serializable validate(Serializable toValidate) throws InvalidValueException {
|
|
if(toValidate instanceof Integer){
|
|
return toValidate;
|
|
}
|
|
Integer integerObj = Integer.getInteger((String) toValidate);
|
|
if(integerObj!=null){
|
|
return integerObj;
|
|
}
|
|
|
|
throw new InvalidValueException(ERROR);
|
|
}
|
|
|
|
}
|