Class Utils
- java.lang.Object
-
- com.jayway.jsonpath.internal.Utils
-
public final class Utils extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseQuietly(java.io.Closeable closeable)static java.lang.Stringconcat(java.lang.CharSequence... strings)static java.lang.Stringescape(java.lang.String str, boolean escapeSingleQuote)static java.lang.Stringhex(char ch)Returns an upper case hexadecimalStringfor the given character.static booleanisEmpty(java.lang.CharSequence cs)Checks if a CharSequence is empty ("") or null.static voidisTrue(boolean expression, java.lang.String message)Validate that the argument condition istrue; otherwise throwing an exception with the specified message.static java.lang.Stringjoin(java.lang.String delimiter, java.lang.Iterable<?> objs)static java.lang.Stringjoin(java.lang.String delimiter, java.lang.String wrap, java.lang.Iterable<?> objs)static byte[]notEmpty(byte[] bytes, java.lang.String message)Validate that the specified argument character sequence is neithernullnor a length of zero (no characters); otherwise throwing an exception with the specified message.static <T extends java.lang.CharSequence>
TnotEmpty(T chars, java.lang.String message)Validate that the specified argument character sequence is neithernullnor a length of zero (no characters); otherwise throwing an exception with the specified message.static <T extends java.lang.CharSequence>
TnotEmpty(T chars, java.lang.String message, java.lang.Object... values)Validate that the specified argument character sequence is neithernullnor a length of zero (no characters); otherwise throwing an exception with the specified message.static <T> TnotNull(T object, java.lang.String message)Validate that the specified argument is notnull; otherwise throwing an exception with the specified message.static <T> TnotNull(T object, java.lang.String message, java.lang.Object... values)Validate that the specified argument is notnull; otherwise throwing an exception with the specified message.static voidonlyOneIsTrue(java.lang.String message, boolean... expressions)Check if one and only one condition is true; otherwise throw an exception with the specified message.static booleanonlyOneIsTrueNonThrow(boolean... expressions)static java.lang.StringtoString(java.lang.Object o)static java.lang.Stringunescape(java.lang.String str)
-
-
-
Method Detail
-
join
public static java.lang.String join(java.lang.String delimiter, java.lang.String wrap, java.lang.Iterable<?> objs)
-
join
public static java.lang.String join(java.lang.String delimiter, java.lang.Iterable<?> objs)
-
concat
public static java.lang.String concat(java.lang.CharSequence... strings)
-
closeQuietly
public static void closeQuietly(java.io.Closeable closeable)
-
escape
public static java.lang.String escape(java.lang.String str, boolean escapeSingleQuote)
-
unescape
public static java.lang.String unescape(java.lang.String str)
-
hex
public static java.lang.String hex(char ch)
Returns an upper case hexadecimalStringfor the given character.- Parameters:
ch- The character to map.- Returns:
- An upper case hexadecimal
String
-
isEmpty
public static boolean isEmpty(java.lang.CharSequence cs)
Checks if a CharSequence is empty ("") or null.
StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = falseNOTE: This method changed in Lang version 2.0. It no longer trims the CharSequence. That functionality is available in isBlank().
- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is empty or null- Since:
- 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence)
-
notNull
public static <T> T notNull(T object, java.lang.String message)Validate that the specified argument is not
null; otherwise throwing an exception with the specified message.Validate.notNull(myObject, "The object must not be null");
- Type Parameters:
T- the object type- Parameters:
object- the object to checkmessage- theString.format(String, Object...)exception message if invalid, not null- Returns:
- the validated object (never
nullfor method chaining) - Throws:
java.lang.NullPointerException- if the object isnull
-
notNull
public static <T> T notNull(T object, java.lang.String message, java.lang.Object... values)Validate that the specified argument is not
null; otherwise throwing an exception with the specified message.Validate.notNull(myObject, "The object must not be null");
- Type Parameters:
T- the object type- Parameters:
object- the object to checkmessage- theString.format(String, Object...)exception message if invalid, not nullvalues- the optional values for the formatted exception message- Returns:
- the validated object (never
nullfor method chaining) - Throws:
java.lang.NullPointerException- if the object isnull
-
isTrue
public static void isTrue(boolean expression, java.lang.String message)Validate that the argument condition is
true; otherwise throwing an exception with the specified message. This method is useful when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.Validate.isTrue(i > 0.0, "The value must be greater than zero: %d", i);
For performance reasons, the long value is passed as a separate parameter and appended to the exception message only in the case of an error.
- Parameters:
expression- the boolean expression to checkmessage-- Throws:
java.lang.IllegalArgumentException- if expression isfalse
-
onlyOneIsTrue
public static void onlyOneIsTrue(java.lang.String message, boolean... expressions)Check if one and only one condition is true; otherwise throw an exception with the specified message.- Parameters:
message- error describing messageexpressions- the boolean expressions to check- Throws:
java.lang.IllegalArgumentException- if zero or more than one expressions are true
-
onlyOneIsTrueNonThrow
public static boolean onlyOneIsTrueNonThrow(boolean... expressions)
-
notEmpty
public static <T extends java.lang.CharSequence> T notEmpty(T chars, java.lang.String message)Validate that the specified argument character sequence is neither
nullnor a length of zero (no characters); otherwise throwing an exception with the specified message.Validate.notEmpty(myString, "The string must not be empty");
- Type Parameters:
T- the character sequence type- Parameters:
chars- the character sequence to check, validated not null by this methodmessage- theString.format(String, Object...)exception message if invalid, not null- Returns:
- the validated character sequence (never
nullmethod for chaining) - Throws:
java.lang.NullPointerException- if the character sequence isnulljava.lang.IllegalArgumentException- if the character sequence is empty
-
notEmpty
public static byte[] notEmpty(byte[] bytes, java.lang.String message)Validate that the specified argument character sequence is neither
nullnor a length of zero (no characters); otherwise throwing an exception with the specified message.Validate.notEmpty(myString, "The string must not be empty");
- Parameters:
bytes- the bytes to check, validated not null by this methodmessage- theString.format(String, Object...)exception message if invalid, not null- Returns:
- the validated character sequence (never
nullmethod for chaining) - Throws:
java.lang.NullPointerException- if the character sequence isnulljava.lang.IllegalArgumentException- if the character sequence is empty
-
notEmpty
public static <T extends java.lang.CharSequence> T notEmpty(T chars, java.lang.String message, java.lang.Object... values)Validate that the specified argument character sequence is neither
nullnor a length of zero (no characters); otherwise throwing an exception with the specified message.Validate.notEmpty(myString, "The string must not be empty");
- Type Parameters:
T- the character sequence type- Parameters:
chars- the character sequence to check, validated not null by this methodmessage- theString.format(String, Object...)exception message if invalid, not nullvalues- the optional values for the formatted exception message, null array not recommended- Returns:
- the validated character sequence (never
nullmethod for chaining) - Throws:
java.lang.NullPointerException- if the character sequence isnulljava.lang.IllegalArgumentException- if the character sequence is empty
-
toString
public static java.lang.String toString(java.lang.Object o)
-
-