-
-
Save rponte/7467072 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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