de.thksystems.validation.beanvalidation.AbstractNotEmptyValidator Maven / Gradle / Ivy
package de.thksystems.validation.beanvalidation;
import java.lang.reflect.Array;
import java.util.Collection;
import org.apache.commons.lang3.StringUtils;
public class AbstractNotEmptyValidator {
protected boolean isNotEmpty(Object fieldValue) {
if (fieldValue == null) {
return false;
}
// Check for empty String
if (fieldValue instanceof CharSequence) {
return StringUtils.isNotEmpty((String) fieldValue);
}
// Check for empty collection
if (fieldValue instanceof Collection>) {
return !((Collection>) fieldValue).isEmpty();
}
// Check for empty array
if (fieldValue.getClass().isArray()) {
return Array.getLength(fieldValue) > 0;
}
// Any other object that is not null
return true;
}
}