Class Utils

java.lang.Object
com.jayway.jsonpath.internal.Utils

public final class Utils extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
     
    static String
    concat(CharSequence... strings)
     
    static String
    escape(String str, boolean escapeSingleQuote)
     
    static String
    hex(char ch)
    Returns an upper case hexadecimal String for the given character.
    static boolean
    Checks if a CharSequence is empty ("") or null.
    static void
    isTrue(boolean expression, String message)
    Validate that the argument condition is true; otherwise throwing an exception with the specified message.
    static String
    join(String delimiter, Iterable<?> objs)
     
    static String
    join(String delimiter, String wrap, Iterable<?> objs)
     
    static byte[]
    notEmpty(byte[] bytes, String message)
    Validate that the specified argument character sequence is neither null nor a length of zero (no characters); otherwise throwing an exception with the specified message.
    static <T extends CharSequence>
    T
    notEmpty(T chars, String message)
    Validate that the specified argument character sequence is neither null nor a length of zero (no characters); otherwise throwing an exception with the specified message.
    static <T extends CharSequence>
    T
    notEmpty(T chars, String message, Object... values)
    Validate that the specified argument character sequence is neither null nor a length of zero (no characters); otherwise throwing an exception with the specified message.
    static <T> T
    notNull(T object, String message)
    Validate that the specified argument is not null; otherwise throwing an exception with the specified message.
    static <T> T
    notNull(T object, String message, Object... values)
    Validate that the specified argument is not null; otherwise throwing an exception with the specified message.
    static void
    onlyOneIsTrue(String message, boolean... expressions)
    Check if one and only one condition is true; otherwise throw an exception with the specified message.
    static boolean
    onlyOneIsTrueNonThrow(boolean... expressions)
     
    static String
     
    static String
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • join

      public static String join(String delimiter, String wrap, Iterable<?> objs)
    • join

      public static String join(String delimiter, Iterable<?> objs)
    • concat

      public static String concat(CharSequence... strings)
    • closeQuietly

      public static void closeQuietly(Closeable closeable)
    • escape

      public static String escape(String str, boolean escapeSingleQuote)
    • unescape

      public static String unescape(String str)
    • hex

      public static String hex(char ch)
      Returns an upper case hexadecimal String for the given character.
      Parameters:
      ch - The character to map.
      Returns:
      An upper case hexadecimal String
    • isEmpty

      public static boolean isEmpty(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  ") = false
       

      NOTE: 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:
      true if 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, 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 check
      message - the String.format(String, Object...) exception message if invalid, not null
      Returns:
      the validated object (never null for method chaining)
      Throws:
      NullPointerException - if the object is null
    • notNull

      public static <T> T notNull(T object, String message, 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 check
      message - the String.format(String, Object...) exception message if invalid, not null
      values - the optional values for the formatted exception message
      Returns:
      the validated object (never null for method chaining)
      Throws:
      NullPointerException - if the object is null
    • isTrue

      public static void isTrue(boolean expression, 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 check
      message -
      Throws:
      IllegalArgumentException - if expression is false
    • onlyOneIsTrue

      public static void onlyOneIsTrue(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 message
      expressions - the boolean expressions to check
      Throws:
      IllegalArgumentException - if zero or more than one expressions are true
    • onlyOneIsTrueNonThrow

      public static boolean onlyOneIsTrueNonThrow(boolean... expressions)
    • notEmpty

      public static <T extends CharSequence> T notEmpty(T chars, String message)

      Validate that the specified argument character sequence is neither 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");
      Type Parameters:
      T - the character sequence type
      Parameters:
      chars - the character sequence to check, validated not null by this method
      message - the String.format(String, Object...) exception message if invalid, not null
      Returns:
      the validated character sequence (never null method for chaining)
      Throws:
      NullPointerException - if the character sequence is null
      IllegalArgumentException - if the character sequence is empty
    • notEmpty

      public static byte[] notEmpty(byte[] bytes, String message)

      Validate that the specified argument character sequence is neither 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");
      Parameters:
      bytes - the bytes to check, validated not null by this method
      message - the String.format(String, Object...) exception message if invalid, not null
      Returns:
      the validated character sequence (never null method for chaining)
      Throws:
      NullPointerException - if the character sequence is null
      IllegalArgumentException - if the character sequence is empty
    • notEmpty

      public static <T extends CharSequence> T notEmpty(T chars, String message, Object... values)

      Validate that the specified argument character sequence is neither 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");
      Type Parameters:
      T - the character sequence type
      Parameters:
      chars - the character sequence to check, validated not null by this method
      message - the String.format(String, Object...) exception message if invalid, not null
      values - the optional values for the formatted exception message, null array not recommended
      Returns:
      the validated character sequence (never null method for chaining)
      Throws:
      NullPointerException - if the character sequence is null
      IllegalArgumentException - if the character sequence is empty
    • toString

      public static String toString(Object o)