Skip to content

Instantly share code, notes, and snippets.

@rponte
Forked from carlosspohr/Validate.java
Created November 14, 2013 13:50
Show Gist options
  • Save rponte/7467072 to your computer and use it in GitHub Desktop.
Save rponte/7467072 to your computer and use it in GitHub Desktop.
public class Validate {
public static boolean not(boolean expression){
return !expression;
}
public static boolean in(String value, String[] options){
return StringUtil.in(value, options);
}
public static boolean isValidEntity(AbstractEntity entity){
return isNotNull(entity) && isNotNull(entity.getId());
}
public static boolean isValidEmail(String email){
return isNotNull(email) && StringUtil.isValidEmail(email);
}
public static boolean isNotNull(Object value){
return !isNull(value);
}
public static boolean isNull(Object value){
return value == null;
}
public static boolean isNullOrEquals(Object from, Object target){
return isNull(from) || eq(from, target);
}
public static boolean isEmpty(String value){
return isNotNull(value) && value.trim().isEmpty();
}
public static boolean isEmpty(Collection<?> collection){
return isNull(collection) || collection.isEmpty();
}
public static boolean isNotEmpty(Collection<?> collection){
return !isEmpty(collection);
}
public static boolean isNullOrEmpty(String value){
return isNull(value) || value.trim().isEmpty();
}
public static boolean gt(String value, int length){
return !isEmpty(value) && value.length() > length;
}
public static boolean eq(Object from, Object target){
return isNotNull(from) && isNotNull(target) && from.equals(target);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment