Example usage for org.apache.commons.validator.routines FloatValidator minValue

List of usage examples for org.apache.commons.validator.routines FloatValidator minValue

Introduction

In this page you can find the example usage for org.apache.commons.validator.routines FloatValidator minValue.

Prototype

public boolean minValue(Float value, float min) 

Source Link

Document

Check if the value is greater than or equal to a minimum.

Usage

From source file:org.mule.modules.validation.ValidationModule.java

/**
 * If the specified <code>value</code> is not a valid {@link Float} throw an exception.
 * <p/>/*from   w  ww.  j  a  v  a  2s .  c  o m*/
 * {@sample.xml ../../../doc/mule-module-validation.xml.sample validation:validate-float}
 *
 * @param value                    Value to validate
 * @param locale                   The locale to use for the format
 * @param pattern                  The pattern used to format the value
 * @param minValue                 The minimum value
 * @param maxValue                 The maximum value
 * @param customExceptionClassName Class name of the exception to throw
 * @throws Exception if not valid
 */
@Processor
public void validateFloat(String value, @Optional @Default("US") Locale locale, @Optional String pattern,
        @Optional Float minValue, @Optional Float maxValue,
        @Optional @Default("org.mule.modules.validation.InvalidException") String customExceptionClassName)
        throws Exception {
    FloatValidator validator = FloatValidator.getInstance();

    Float newValue = null;
    if (pattern != null) {
        newValue = validator.validate(value, pattern, locale.getJavaLocale());
    } else {
        newValue = validator.validate(value, locale.getJavaLocale());
    }

    if (newValue == null) {
        throw buildException(customExceptionClassName);
    }
    if (minValue != null) {
        if (!validator.minValue(newValue, minValue)) {
            throw buildException(customExceptionClassName);
        }
    }
    if (maxValue != null) {
        if (!validator.maxValue(newValue, maxValue)) {
            throw buildException(customExceptionClassName);
        }
    }
}