Browse Source

provide no varargs overload for notEmpty so common case does not allocate (#752)

pull/763/head
Richard Startin 3 years ago committed by GitHub
parent
commit
65a3f5a9e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      json-path/src/main/java/com/jayway/jsonpath/internal/Utils.java

40
json-path/src/main/java/com/jayway/jsonpath/internal/Utils.java

@ -298,6 +298,25 @@ public final class Utils {
//
//---------------------------------------------------------
/**
* <p>Validate that the specified argument is not {@code null};
* otherwise throwing an exception with the specified message.
* <p/>
* <pre>Validate.notNull(myObject, "The object must not be null");</pre>
*
* @param <T> 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> T notNull(T object, String message) {
if (object == null) {
throw new IllegalArgumentException(message);
}
return object;
}
/**
* <p>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;
}
/**
* <p>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.
* <p/>
* <pre>Validate.notEmpty(myString, "The string must not be empty");</pre>
*
* @param <T> 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 extends CharSequence> T notEmpty(T chars, String message) {
if (chars == null || chars.length() == 0) {
throw new IllegalArgumentException(message);
}
return chars;
}
/**
* <p>Validate that the specified argument character sequence is
* neither {@code null} nor a length of zero (no characters);

Loading…
Cancel
Save