package jakiro.util; public class Validate { private static final String DEFAULT_IS_NULL_EX_MESSAGE = "The validated object is null"; private static final String DEFAULT_IS_TRUE_EX_MESSAGE = "The validated expression is false"; private static final String DEFAULT_NOT_BLANK_EX_MESSAGE = "The validated character sequence is blank"; public static <T> T notNull(final T object) { return notNull(object, DEFAULT_IS_NULL_EX_MESSAGE); } public static <T> T notNull(final T object, final String message, final Object... values) { if (object == null) { throw new NullPointerException(String.format(message, values)); } return object; } public static void isTrue(final boolean expression, final String message, final Object... values) { if (expression == false) { throw new IllegalArgumentException(String.format(message, values)); } } public static void isTrue(final boolean expression) { if (expression == false) { throw new IllegalArgumentException(DEFAULT_IS_TRUE_EX_MESSAGE); } } public static <T extends CharSequence> T notBlank(final T chars) { return notBlank(chars, DEFAULT_NOT_BLANK_EX_MESSAGE); } public static <T extends CharSequence> T notBlank(final T chars, final String message, final Object... values) { if (chars == null) { throw new NullPointerException(String.format(message, values)); } if (StringUtils.isBlank(chars)) { throw new IllegalArgumentException(String.format(message, values)); } return chars; } }