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

org.droitateddb.validation.LengthValidator 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;

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

    public static final int ERROR_CODE = 1;

    @Override
    public ValidationResult onValidate(Length length, String data) {
        long minLength = length.min();
        long maxLength = length.max();
        if (data == null) {
            return ValidationResult.valid();
        }
        if (minLength > -1 && data.length() < minLength) {
            return ValidationResult.invalid(ERROR_CODE, "The given data is to short. It should be between " + minLength + " and " + maxLength + " characters long.");
        }
        if (maxLength > -1 && data.length() > maxLength) {
            return ValidationResult.invalid(ERROR_CODE, "The given data is to long. It should be between " + minLength + " and " + maxLength + " characters long.");
        }
        return ValidationResult.valid();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy