All Downloads are FREE. Search and download functionalities are using the official Maven repository.

play.data.validation.MinSizeCheck Maven / Gradle / Ivy

There is a newer version: 2.6.3
Show newest version
package play.data.validation;

import net.sf.oval.Validator;
import net.sf.oval.configuration.annotation.AbstractAnnotationCheck;
import net.sf.oval.context.OValContext;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("serial")
public class MinSizeCheck extends AbstractAnnotationCheck {

    static final String mes = "validation.minSize";

    int minSize;

    @Override
    public void configure(MinSize annotation) {
        this.minSize = annotation.value();
        setMessage(annotation.message());
    }

    @Override
    public boolean isSatisfied(Object validatedObject, Object value, OValContext context, Validator validator) {
        requireMessageVariablesRecreation();
        if (value == null || value.toString().length() == 0) {
            return true;
        }
        return value.toString().length() >= minSize;
    }

    @Override
    public Map createMessageVariables() {
        Map messageVariables = new HashMap<>();
        messageVariables.put("minSize", Integer.toString(minSize));
        return messageVariables;
    }
   
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy