Class StringUtils


  • @API(status=INTERNAL,
         since="1.0")
    public final class StringUtils
    extends java.lang.Object
    Collection of utilities for working with Strings, CharSequences, etc.

    DISCLAIMER

    These utilities are intended solely for usage within the JUnit framework itself. Any usage by external parties is not supported. Use at your own risk!

    Since:
    1.0
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean containsIsoControlCharacter​(java.lang.String str)
      Determine if the supplied String contains any ISO control characters.
      static boolean containsWhitespace​(java.lang.String str)
      Determine if the supplied String contains any whitespace characters.
      static java.lang.String defaultToString​(java.lang.Object obj)
      Convert the supplied Object to a default String representation using the following algorithm.
      static boolean doesNotContainIsoControlCharacter​(java.lang.String str)
      Determine if the supplied String does not contain any ISO control characters.
      static boolean doesNotContainWhitespace​(java.lang.String str)
      Determine if the supplied String does not contain any whitespace characters.
      static boolean isBlank​(java.lang.String str)
      Determine if the supplied String is blank (i.e., null or consisting only of whitespace characters).
      static boolean isNotBlank​(java.lang.String str)
      Determine if the supplied String is not blank.
      static java.lang.String nullSafeToString​(java.lang.Object obj)
      Convert the supplied Object to a String using the following algorithm.
      static java.lang.String replaceIsoControlCharacters​(java.lang.String str, java.lang.String replacement)
      Replace all ISO control characters in the supplied String.
      static java.lang.String replaceWhitespaceCharacters​(java.lang.String str, java.lang.String replacement)
      Replace all whitespace characters in the supplied String.
      • Methods inherited from class java.lang.Object

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

      • isBlank

        public static boolean isBlank​(java.lang.String str)
        Determine if the supplied String is blank (i.e., null or consisting only of whitespace characters).
        Parameters:
        str - the string to check; may be null
        Returns:
        true if the string is blank
        See Also:
        isNotBlank(String)
      • isNotBlank

        public static boolean isNotBlank​(java.lang.String str)
        Determine if the supplied String is not blank.
        Parameters:
        str - the string to check; may be null
        Returns:
        true if the string is not blank
        See Also:
        isBlank(String)
      • containsWhitespace

        public static boolean containsWhitespace​(java.lang.String str)
        Determine if the supplied String contains any whitespace characters.
        Parameters:
        str - the string to check; may be null
        Returns:
        true if the string contains whitespace
        See Also:
        containsIsoControlCharacter(String), Character.isWhitespace(int)
      • doesNotContainWhitespace

        public static boolean doesNotContainWhitespace​(java.lang.String str)
        Determine if the supplied String does not contain any whitespace characters.
        Parameters:
        str - the string to check; may be null
        Returns:
        true if the string does not contain whitespace
        See Also:
        containsWhitespace(String), containsIsoControlCharacter(String), Character.isWhitespace(int)
      • containsIsoControlCharacter

        public static boolean containsIsoControlCharacter​(java.lang.String str)
        Determine if the supplied String contains any ISO control characters.
        Parameters:
        str - the string to check; may be null
        Returns:
        true if the string contains an ISO control character
        See Also:
        containsWhitespace(String), Character.isISOControl(int)
      • doesNotContainIsoControlCharacter

        public static boolean doesNotContainIsoControlCharacter​(java.lang.String str)
        Determine if the supplied String does not contain any ISO control characters.
        Parameters:
        str - the string to check; may be null
        Returns:
        true if the string does not contain an ISO control character
        See Also:
        containsIsoControlCharacter(String), containsWhitespace(String), Character.isISOControl(int)
      • nullSafeToString

        public static java.lang.String nullSafeToString​(java.lang.Object obj)
        Convert the supplied Object to a String using the following algorithm.
        • If the supplied object is null, this method returns "null".
        • If the supplied object is a primitive array, the appropriate Arrays#toString(...) variant will be used to convert it to a String.
        • If the supplied object is an object array, Arrays#deepToString(Object[]) will be used to convert it to a String.
        • Otherwise, the result of invoking toString() on the object will be returned.
        • If any of the above results in an exception, this method delegates to defaultToString(Object)
        Parameters:
        obj - the object to convert to a String; may be null
        Returns:
        a String representation of the supplied object; never null
        See Also:
        Arrays.deepToString(Object[]), ClassUtils.nullSafeToString(Class...)
      • defaultToString

        public static java.lang.String defaultToString​(java.lang.Object obj)
        Convert the supplied Object to a default String representation using the following algorithm.
        • If the supplied object is null, this method returns "null".
        • Otherwise, the String returned by this method will be generated analogous to the default implementation of Object.toString() by using the supplied object's class name and hash code as follows: obj.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj))
        Parameters:
        obj - the object to convert to a String; may be null
        Returns:
        the default String representation of the supplied object; never null
        See Also:
        nullSafeToString(Object), ClassUtils.nullSafeToString(Class...)
      • replaceIsoControlCharacters

        @API(status=INTERNAL,
             since="1.4")
        public static java.lang.String replaceIsoControlCharacters​(java.lang.String str,
                                                                   java.lang.String replacement)
        Replace all ISO control characters in the supplied String.
        Parameters:
        str - the string in which to perform the replacement; may be null
        replacement - the replacement string; never null
        Returns:
        the supplied string with all control characters replaced, or null if the supplied string was null
        Since:
        1.4
      • replaceWhitespaceCharacters

        @API(status=INTERNAL,
             since="1.4")
        public static java.lang.String replaceWhitespaceCharacters​(java.lang.String str,
                                                                   java.lang.String replacement)
        Replace all whitespace characters in the supplied String.
        Parameters:
        str - the string in which to perform the replacement; may be null
        replacement - the replacement string; never null
        Returns:
        the supplied string with all whitespace characters replaced, or null if the supplied string was null
        Since:
        1.4