@API(status=INTERNAL,
since="1.0")
public final class StringUtils
extends java.lang.Object
Strings
,
CharSequences
, etc.
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!
Modifier and Type | Field and Description |
---|---|
private static java.util.regex.Pattern |
ISO_CONTROL_PATTERN |
private static java.util.regex.Pattern |
WHITESPACE_PATTERN |
Modifier | Constructor and Description |
---|---|
private |
StringUtils() |
Modifier and Type | Method and Description |
---|---|
(package private) static java.util.regex.Pattern |
compileIsoControlPattern()
Guard against "IllegalArgumentException: Unsupported flags: 256" errors.
|
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 . |
private static final java.util.regex.Pattern ISO_CONTROL_PATTERN
private static final java.util.regex.Pattern WHITESPACE_PATTERN
static java.util.regex.Pattern compileIsoControlPattern()
public static boolean isBlank(java.lang.String str)
String
is blank (i.e.,
null
or consisting only of whitespace characters).str
- the string to check; may be null
true
if the string is blankisNotBlank(String)
public static boolean isNotBlank(java.lang.String str)
String
is not blank.str
- the string to check; may be null
true
if the string is not blankisBlank(String)
public static boolean containsWhitespace(java.lang.String str)
String
contains any whitespace characters.str
- the string to check; may be null
true
if the string contains whitespacecontainsIsoControlCharacter(String)
,
Character.isWhitespace(int)
public static boolean doesNotContainWhitespace(java.lang.String str)
String
does not contain any whitespace
characters.str
- the string to check; may be null
true
if the string does not contain whitespacecontainsWhitespace(String)
,
containsIsoControlCharacter(String)
,
Character.isWhitespace(int)
public static boolean containsIsoControlCharacter(java.lang.String str)
String
contains any ISO control characters.str
- the string to check; may be null
true
if the string contains an ISO control charactercontainsWhitespace(String)
,
Character.isISOControl(int)
public static boolean doesNotContainIsoControlCharacter(java.lang.String str)
String
does not contain any ISO control
characters.str
- the string to check; may be null
true
if the string does not contain an ISO control charactercontainsIsoControlCharacter(String)
,
containsWhitespace(String)
,
Character.isISOControl(int)
public static java.lang.String nullSafeToString(java.lang.Object obj)
Object
to a String
using the
following algorithm.
null
, this method returns "null"
.Arrays#toString(...)
variant will be used to convert it to a String.Arrays#deepToString(Object[])
will be used to convert it to a String.toString()
on the object
will be returned.defaultToString(Object)
obj
- the object to convert to a String; may be null
null
Arrays.deepToString(Object[])
,
ClassUtils.nullSafeToString(Class...)
public static java.lang.String defaultToString(java.lang.Object obj)
Object
to a default String
representation using the following algorithm.
null
, this method returns "null"
.Object.toString()
by using the supplied
object's class name and hash code as follows:
obj.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj))
obj
- the object to convert to a String; may be null
null
nullSafeToString(Object)
,
ClassUtils.nullSafeToString(Class...)
@API(status=INTERNAL, since="1.4") public static java.lang.String replaceIsoControlCharacters(java.lang.String str, java.lang.String replacement)
String
.str
- the string in which to perform the replacement; may be null
replacement
- the replacement string; never null
null
if the supplied string was null
@API(status=INTERNAL, since="1.4") public static java.lang.String replaceWhitespaceCharacters(java.lang.String str, java.lang.String replacement)
String
.str
- the string in which to perform the replacement; may be null
replacement
- the replacement string; never null
null
if the supplied string was null