org.mongodb.morphia.query.validation.PatternValueValidator 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 java.util.regex.Pattern;
import static java.lang.String.format;
/**
* Validates query values that are Pattern to check the field type is a String.
*/
public final class PatternValueValidator extends ValueValidator {
private static final PatternValueValidator INSTANCE = new PatternValueValidator();
private PatternValueValidator() {
}
/**
* Get the instance.
*
* @return the Singleton instance of this validator
*/
public static PatternValueValidator getInstance() {
return INSTANCE;
}
@Override
protected Class getRequiredValueType() {
return Pattern.class;
}
@Override
protected void validate(final Class type, final Object value, final List validationFailures) {
if (!String.class.equals(type)) {
validationFailures.add(new ValidationFailure(format("Patterns can only be used as query values for Strings")));
}
}
}