org.mongodb.morphia.query.validation.IntegerTypeValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of morphia Show documentation
Show all versions of morphia Show documentation
Java Object Document Mapper for MongoDB
The newest version!
package org.mongodb.morphia.query.validation;
import java.util.List;
import static java.lang.String.format;
/**
* If the Type is some sort of integer-compatible field (see {@code getTypeClasses}) then this validator will check if the value is of the
* correct type for this field.
*/
public final class IntegerTypeValidator extends TypeValidator {
private static final IntegerTypeValidator INSTANCE = new IntegerTypeValidator();
private IntegerTypeValidator() {
}
/**
* Get the instance.
*
* @return the Singleton instance of this validator
*/
public static IntegerTypeValidator getInstance() {
return INSTANCE;
}
@Override
protected boolean appliesTo(final Class type) {
return type == int.class || type == Integer.class;
}
@Override
protected void validate(final Class type, final Object value, final List validationFailures) {
if (Integer.class != value.getClass()) {
validationFailures.add(new ValidationFailure(format("When type is one of the integer types the value should be an Integer. "
+ "Type was %s and value '%s' was a %s", type, value, value.getClass())));
}
}
}