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

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

There is a newer version: 2.6.2
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;

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

    static final String mes = "validation.isTrue";

    @Override
    public void configure(IsTrue isTrue) {
        setMessage(isTrue.message());
    }

    @Override
    public boolean isSatisfied(Object validatedObject, Object value, OValContext context, Validator validator) {
        if (value == null) {
            return false;
        }
        if (value instanceof String) {
            try {
                return Boolean.parseBoolean(value.toString());
            } catch (Exception e) {
                return false;
            }
        }
        if (value instanceof Number) {
            try {
                return ((Number) value).doubleValue() != 0;
            } catch (Exception e) {
                return false;
            }
        }
        if (value instanceof Boolean) {
            try {
                return ((Boolean) value);
            } catch (Exception e) {
                return false;
            }
        }
        return false;
    }
   
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy