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

de.thksystems.validation.beanvalidation.AbstractNotEmptyValidator Maven / Gradle / Ivy

Go to download

Commons for persistence, hibernate, xstreams, enterprise, spring, servlets, ...

There is a newer version: 3.9.0
Show newest version
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;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy