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

org.droitateddb.validation.MaxValidator Maven / Gradle / Ivy

Go to download

droitatedDB is a lightweight framework, which frees you from the burden of dealing with Androids SQLite database directly if you don't want to and let's you access it directly if you have to.

The newest version!
package org.droitateddb.validation;

import java.math.BigDecimal;

/**
 * Implementation of the @Max validation annotation
 *
 * @author Falk Appel
 * @author Alexander Frank
 */
public class MaxValidator implements CustomValidator {

    public static final int ERROR_CODE = 3;

    @Override
    public ValidationResult onValidate(Max annotation, Number toByValidated) {
        long max = annotation.value();

        if (toByValidated == null) {
            return ValidationResult.valid();
        }

        if (new BigDecimal(toByValidated.toString()).compareTo(new BigDecimal(max)) <= 0) {
            return ValidationResult.valid();
        }
        return ValidationResult.invalid(ERROR_CODE, "The field as to be less or equal to " + max);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy