diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/Utils.java b/json-path/src/main/java/com/jayway/jsonpath/internal/Utils.java index 20663bb7..3e54c49f 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/Utils.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/Utils.java @@ -298,6 +298,25 @@ public final class Utils { // //--------------------------------------------------------- + /** + *

Validate that the specified argument is not {@code null}; + * otherwise throwing an exception with the specified message. + *

+ *

Validate.notNull(myObject, "The object must not be null");
+ * + * @param the object type + * @param object the object to check + * @param message the {@link String#format(String, Object...)} exception message if invalid, not null + * @return the validated object (never {@code null} for method chaining) + * @throws NullPointerException if the object is {@code null} + */ + public static T notNull(T object, String message) { + if (object == null) { + throw new IllegalArgumentException(message); + } + return object; + } + /** *

Validate that the specified argument is not {@code null}; * otherwise throwing an exception with the specified message. @@ -363,6 +382,27 @@ public final class Utils { return 1 == count; } + /** + *

Validate that the specified argument character sequence is + * neither {@code null} nor a length of zero (no characters); + * otherwise throwing an exception with the specified message. + *

+ *

Validate.notEmpty(myString, "The string must not be empty");
+ * + * @param the character sequence type + * @param chars the character sequence to check, validated not null by this method + * @param message the {@link String#format(String, Object...)} exception message if invalid, not null + * @return the validated character sequence (never {@code null} method for chaining) + * @throws NullPointerException if the character sequence is {@code null} + * @throws IllegalArgumentException if the character sequence is empty + */ + public static T notEmpty(T chars, String message) { + if (chars == null || chars.length() == 0) { + throw new IllegalArgumentException(message); + } + return chars; + } + /** *

Validate that the specified argument character sequence is * neither {@code null} nor a length of zero (no characters);