com.arconsis.android.datarobot.validation.LengthValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datarobot.api Show documentation
Show all versions of datarobot.api Show documentation
Datarobot for Android 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 com.arconsis.android.datarobot.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();
}
}