Package org.junit.platform.commons.util
Class StringUtils
- java.lang.Object
-
- org.junit.platform.commons.util.StringUtils
-
@API(status=INTERNAL, since="1.0") public final class StringUtils extends Object
Collection of utilities for working withStrings,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 booleancontainsIsoControlCharacter(String str)Determine if the suppliedStringcontains any ISO control characters.static booleancontainsWhitespace(String str)Determine if the suppliedStringcontains any whitespace characters.static StringdefaultToString(Object obj)Convert the suppliedObjectto a defaultStringrepresentation using the following algorithm.static booleandoesNotContainIsoControlCharacter(String str)Determine if the suppliedStringdoes not contain any ISO control characters.static booleandoesNotContainWhitespace(String str)Determine if the suppliedStringdoes not contain any whitespace characters.static booleanisBlank(String str)Determine if the suppliedStringis blank (i.e.,nullor consisting only of whitespace characters).static booleanisNotBlank(String str)static StringnullSafeToString(Object obj)Convert the suppliedObjectto aStringusing the following algorithm.static StringreplaceIsoControlCharacters(String str, String replacement)Replace all ISO control characters in the suppliedString.static StringreplaceWhitespaceCharacters(String str, String replacement)Replace all whitespace characters in the suppliedString.
-
-
-
Method Detail
-
isBlank
public static boolean isBlank(String str)
Determine if the suppliedStringis blank (i.e.,nullor consisting only of whitespace characters).- Parameters:
str- the string to check; may benull- Returns:
trueif the string is blank- See Also:
isNotBlank(String)
-
isNotBlank
public static boolean isNotBlank(String str)
- Parameters:
str- the string to check; may benull- Returns:
trueif the string is not blank- See Also:
isBlank(String)
-
containsWhitespace
public static boolean containsWhitespace(String str)
Determine if the suppliedStringcontains any whitespace characters.- Parameters:
str- the string to check; may benull- Returns:
trueif the string contains whitespace- See Also:
containsIsoControlCharacter(String),Character.isWhitespace(int)
-
doesNotContainWhitespace
public static boolean doesNotContainWhitespace(String str)
Determine if the suppliedStringdoes not contain any whitespace characters.- Parameters:
str- the string to check; may benull- Returns:
trueif the string does not contain whitespace- See Also:
containsWhitespace(String),containsIsoControlCharacter(String),Character.isWhitespace(int)
-
containsIsoControlCharacter
public static boolean containsIsoControlCharacter(String str)
Determine if the suppliedStringcontains any ISO control characters.- Parameters:
str- the string to check; may benull- Returns:
trueif the string contains an ISO control character- See Also:
containsWhitespace(String),Character.isISOControl(int)
-
doesNotContainIsoControlCharacter
public static boolean doesNotContainIsoControlCharacter(String str)
Determine if the suppliedStringdoes not contain any ISO control characters.- Parameters:
str- the string to check; may benull- Returns:
trueif the string does not contain an ISO control character- See Also:
containsIsoControlCharacter(String),containsWhitespace(String),Character.isISOControl(int)
-
nullSafeToString
public static String nullSafeToString(Object obj)
Convert the suppliedObjectto aStringusing 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 benull- Returns:
- a String representation of the supplied object; never
null - See Also:
Arrays.deepToString(Object[]),ClassUtils.nullSafeToString(Class...)
- If the supplied object is
-
defaultToString
public static String defaultToString(Object obj)
Convert the suppliedObjectto a defaultStringrepresentation 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 benull- Returns:
- the default String representation of the supplied object; never
null - See Also:
nullSafeToString(Object),ClassUtils.nullSafeToString(Class...)
- If the supplied object is
-
replaceIsoControlCharacters
@API(status=INTERNAL, since="1.4") public static String replaceIsoControlCharacters(String str, String replacement)
Replace all ISO control characters in the suppliedString.- Parameters:
str- the string in which to perform the replacement; may benullreplacement- the replacement string; nevernull- Returns:
- the supplied string with all control characters replaced, or
nullif the supplied string wasnull - Since:
- 1.4
-
replaceWhitespaceCharacters
@API(status=INTERNAL, since="1.4") public static String replaceWhitespaceCharacters(String str, String replacement)
Replace all whitespace characters in the suppliedString.- Parameters:
str- the string in which to perform the replacement; may benullreplacement- the replacement string; nevernull- Returns:
- the supplied string with all whitespace characters replaced, or
nullif the supplied string wasnull - Since:
- 1.4
-
-