Top Description Inners Fields Constructors Methods
org.junit.platform.commons.util

public final Class StringUtils

extends Object
Class Inheritance
Annotations
@API
status:INTERNAL
since:1.0
Static Imports
java.util.regex.Pattern.UNICODE_CHARACTER_CLASS, org.apiguardian.api.API.Status.INTERNAL

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
private static record
public static interface
StringUtils.TwoPartSplitResult

The result of splitting a string into up to two parts.

Field Summary

Modifier and TypeField and Description
private static final Pattern
private static final Pattern

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static Pattern
compileIsoControlPattern()

Guard against "IllegalArgumentException: Unsupported flags: 256" errors.

public static boolean

Returns:

true if the string contains an ISO control character
containsIsoControlCharacter
(@Nullable String
the string to check; may be null
str
)

Determine if the supplied String contains any ISO control characters.

public static boolean

Returns:

true if the string contains whitespace
containsWhitespace
(@Nullable String
the string to check; may be null
str
)

Determine if the supplied String contains any whitespace characters.

public static String

Returns:

the default String representation of the supplied object; never null
defaultToString
(@Nullable Object
the object to convert to a String; may be null
obj
)

Convert the supplied Object to a default String representation using the following algorithm.

public static boolean

Returns:

true if the string does not contain an ISO control character
doesNotContainIsoControlCharacter
(@Nullable String
the string to check; may be null
str
)

Determine if the supplied String does not contain any ISO control characters.

public static boolean

Returns:

true if the string does not contain whitespace
doesNotContainWhitespace
(@Nullable String
the string to check; may be null
str
)

Determine if the supplied String does not contain any whitespace characters.

public static boolean

Returns:

true if the string is blank
isBlank
(@Nullable String
the string to check; may be null
str
)

Determine if the supplied String is blank (i.e., null or consisting only of whitespace characters).

public static boolean

Returns:

true if the string is not blank
isNotBlank
(@Nullable String
the string to check; may be null
str
)

Determine if the supplied String is not blank.

public static String

Returns:

a String representation of the supplied object; never null
nullSafeToString
(@Nullable Object
the object to convert to a String; may be null
obj
)

Convert the supplied Object to a String using the following algorithm.

public static @Nullable String

Returns:

the supplied string with all control characters replaced, or null if the supplied string was null
replaceIsoControlCharacters
(@Nullable String
the string in which to perform the replacement; may be null
str
,
String
the replacement string; never null
replacement
)

Replace all ISO control characters in the supplied String.

public static @Nullable String

Returns:

the supplied string with all whitespace characters replaced, or null if the supplied string was null
replaceWhitespaceCharacters
(@Nullable String
the string in which to perform the replacement; may be null
str
,
String
the replacement string; never null
replacement
)

Replace all whitespace characters in the supplied String.

public static StringUtils.TwoPartSplitResult
splitIntoTwo(char
the separator character
separator
,
String
the value to split; never null
value
)

Split the supplied String into up to two parts using the supplied separator character.

public static StringUtils.TwoPartSplitResult
splitIntoTwo(String
the separator string; never null
separator
,
String
the value to split; never null
value
)

Split the supplied String into up to two parts using the supplied separator string.

private static StringUtils.TwoPartSplitResult
splitIntoTwo(String value, int index, int length)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ISO_CONTROL_PATTERNback to summary
private static final Pattern ISO_CONTROL_PATTERN
WHITESPACE_PATTERNback to summary
private static final Pattern WHITESPACE_PATTERN

Constructor Detail

StringUtilsback to summary
private StringUtils()

Method Detail

compileIsoControlPatternback to summary
pack-priv static Pattern compileIsoControlPattern()

Guard against "IllegalArgumentException: Unsupported flags: 256" errors.

See Also
#1800
containsIsoControlCharacterback to summary
public static boolean containsIsoControlCharacter(@Nullable String str)

Determine if the supplied String contains any ISO control characters.

Parameters
str:@Nullable String

the string to check; may be null

Returns:boolean

true if the string contains an ISO control character

Annotations
@Contract:null -> false
See Also
containsWhitespace(String), Character#isISOControl(int)
containsWhitespaceback to summary
public static boolean containsWhitespace(@Nullable String str)

Determine if the supplied String contains any whitespace characters.

Parameters
str:@Nullable String

the string to check; may be null

Returns:boolean

true if the string contains whitespace

Annotations
@Contract:null -> false
See Also
containsIsoControlCharacter(String), Character#isWhitespace(int)
defaultToStringback to summary
public static String defaultToString(@Nullable 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:@Nullable Object

the object to convert to a String; may be null

Returns:String

the default String representation of the supplied object; never null

See Also
nullSafeToString(Object), ClassUtils#nullSafeToString(Class...)
doesNotContainIsoControlCharacterback to summary
public static boolean doesNotContainIsoControlCharacter(@Nullable String str)

Determine if the supplied String does not contain any ISO control characters.

Parameters
str:@Nullable String

the string to check; may be null

Returns:boolean

true if the string does not contain an ISO control character

Annotations
@Contract:null -> true
See Also
containsIsoControlCharacter(String), containsWhitespace(String), Character#isISOControl(int)
doesNotContainWhitespaceback to summary
public static boolean doesNotContainWhitespace(@Nullable String str)

Determine if the supplied String does not contain any whitespace characters.

Parameters
str:@Nullable String

the string to check; may be null

Returns:boolean

true if the string does not contain whitespace

Annotations
@Contract:null -> true
See Also
containsWhitespace(String), containsIsoControlCharacter(String), Character#isWhitespace(int)
isBlankback to summary
public static boolean isBlank(@Nullable String str)

Determine if the supplied String is blank (i.e., null or consisting only of whitespace characters).

Parameters
str:@Nullable String

the string to check; may be null

Returns:boolean

true if the string is blank

Annotations
@Contract:null -> true
See Also
String#isBlank(), isNotBlank(String)
isNotBlankback to summary
public static boolean isNotBlank(@Nullable String str)

Determine if the supplied String is not blank.

Parameters
str:@Nullable String

the string to check; may be null

Returns:boolean

true if the string is not blank

Annotations
@Contract:null -> false
See Also
isBlank(String)
nullSafeToStringback to summary
public static String nullSafeToString(@Nullable 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, toString() will be invoked on the object. If the result is non-null, that result will be returned. If the result is null, "null" will be returned.
  • If any of the above results in an exception, this method delegates to defaultToString(Object)
Parameters
obj:@Nullable Object

the object to convert to a String; may be null

Returns:String

a String representation of the supplied object; never null

See Also
Arrays#deepToString(Object[]), ClassUtils#nullSafeToString(Class...)
replaceIsoControlCharactersback to summary
public static @Nullable String replaceIsoControlCharacters(@Nullable String str, String replacement)

Replace all ISO control characters in the supplied String.

Parameters
str:@Nullable String

the string in which to perform the replacement; may be null

replacement:String

the replacement string; never null

Returns:@Nullable String

the supplied string with all control characters replaced, or null if the supplied string was null

Annotations
@API
status:INTERNAL
since:1.4
@Contract:null, _ -> null; !null, _ -> !null
Since
1.4
replaceWhitespaceCharactersback to summary
public static @Nullable String replaceWhitespaceCharacters(@Nullable String str, String replacement)

Replace all whitespace characters in the supplied String.

Parameters
str:@Nullable String

the string in which to perform the replacement; may be null

replacement:String

the replacement string; never null

Returns:@Nullable String

the supplied string with all whitespace characters replaced, or null if the supplied string was null

Annotations
@API
status:INTERNAL
since:1.4
@Contract:null, _ -> null; !null, _ -> !null
Since
1.4
splitIntoTwoback to summary
public static StringUtils.TwoPartSplitResult splitIntoTwo(char separator, String value)

Split the supplied String into up to two parts using the supplied separator character.

Parameters
separator:char

the separator character

value:String

the value to split; never null

Annotations
@API
status:INTERNAL
since:1.11
Since
1.11
splitIntoTwoback to summary
public static StringUtils.TwoPartSplitResult splitIntoTwo(String separator, String value)

Split the supplied String into up to two parts using the supplied separator string.

Parameters
separator:String

the separator string; never null

value:String

the value to split; never null

Annotations
@API
status:INTERNAL
since:1.11
Since
1.11
splitIntoTwoback to summary
private static StringUtils.TwoPartSplitResult splitIntoTwo(String value, int index, int length)
org.junit.platform.commons.util back to summary

private final Record StringUtils.OnePart

extends Record
implements TwoPartSplitResult
Class Inheritance
All Implemented Interfaces
org.junit.platform.commons.util.StringUtils.TwoPartSplitResult
Record Components
value:String 

Field Summary

Modifier and TypeField and Description
private final String
value

Record Component accessed by value().

Constructor Summary

AccessConstructor and Description
private
OnePart(String value)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public <T> T
map(Function<String, ? extends T> onePartMapper, BiFunction<String, String, ? extends T> twoPartsMapper)

Implements org.junit.platform.commons.util.StringUtils.TwoPartSplitResult.map.

Map the result of splitting a string into up to two parts.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

public String
value()

Record Component getter of value.

Field Detail

valueback to summary
private final String value

Record Component accessed by value().

Constructor Detail

OnePartback to summary
private OnePart(String value)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

mapback to summary
public <T> T map(Function<String, ? extends T> onePartMapper, BiFunction<String, String, ? extends T> twoPartsMapper)

Implements org.junit.platform.commons.util.StringUtils.TwoPartSplitResult.map.

Doc from org.junit.platform.commons.util.StringUtils.TwoPartSplitResult.map.

Map the result of splitting a string into up to two parts.

Annotations
@Override
toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

valueback to summary
public String value()

Record Component getter of value.

org.junit.platform.commons.util back to summary

private final Record StringUtils.TwoParts

extends Record
implements TwoPartSplitResult
Class Inheritance
All Implemented Interfaces
org.junit.platform.commons.util.StringUtils.TwoPartSplitResult
Record Components
first:String 
second:String 

Field Summary

Modifier and TypeField and Description
private final String
first

Record Component accessed by first().

private final String
second

Record Component accessed by second().

Constructor Summary

AccessConstructor and Description
private
TwoParts(String first, String second)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public String
first()

Record Component getter of first.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public <T> T
map(Function<String, ? extends T> onePartMapper, BiFunction<String, String, ? extends T> twoPartsMapper)

Implements org.junit.platform.commons.util.StringUtils.TwoPartSplitResult.map.

Map the result of splitting a string into up to two parts.

public String
second()

Record Component getter of second.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

firstback to summary
private final String first

Record Component accessed by first().

secondback to summary
private final String second

Record Component accessed by second().

Constructor Detail

TwoPartsback to summary
private TwoParts(String first, String second)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
firstback to summary
public String first()

Record Component getter of first.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

mapback to summary
public <T> T map(Function<String, ? extends T> onePartMapper, BiFunction<String, String, ? extends T> twoPartsMapper)

Implements org.junit.platform.commons.util.StringUtils.TwoPartSplitResult.map.

Doc from org.junit.platform.commons.util.StringUtils.TwoPartSplitResult.map.

Map the result of splitting a string into up to two parts.

Annotations
@Override
secondback to summary
public String second()

Record Component getter of second.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

org.junit.platform.commons.util back to summary

public sealed Interface StringUtils.TwoPartSplitResult

permits OnePart, TwoParts
Known Direct Implementers
org.junit.platform.commons.util.StringUtils.OnePart, org.junit.platform.commons.util.StringUtils.TwoParts
Annotations
@API
status:INTERNAL
since:1.11

The result of splitting a string into up to two parts.
Since
1.11
See Also
StringUtils#splitIntoTwo(char, String), StringUtils#splitIntoTwo(String, String)

Method Summary

Modifier and TypeMethod and Description
public <T> T
map(Function<String, ? extends T>
the mapper to use if the string was split into a single part
onePartMapper
,
BiFunction<String, String, ? extends T>
the mapper to use if the string was split into two parts
twoPartsMapper
)

Map the result of splitting a string into up to two parts.

public default <T> T
mapTwo(Supplier<? extends RuntimeException>
the exception creator to use if the string was split into a single part
onePartExceptionCreator
,
BiFunction<String, String, ? extends T>
the mapper to use if the string was split into two parts
twoPartsMapper
)

Map the result of splitting a string into two parts or throw an exception.

Method Detail

mapback to summary
public <T> T map(Function<String, ? extends T> onePartMapper, BiFunction<String, String, ? extends T> twoPartsMapper)

Map the result of splitting a string into up to two parts.

Parameters
onePartMapper:Function<String, ? extends T>

the mapper to use if the string was split into a single part

twoPartsMapper:BiFunction<String, String, ? extends T>

the mapper to use if the string was split into two parts

mapTwoback to summary
public default <T> T mapTwo(Supplier<? extends RuntimeException> onePartExceptionCreator, BiFunction<String, String, ? extends T> twoPartsMapper)

Map the result of splitting a string into two parts or throw an exception.

Parameters
onePartExceptionCreator:Supplier<? extends RuntimeException>

the exception creator to use if the string was split into a single part

twoPartsMapper:BiFunction<String, String, ? extends T>

the mapper to use if the string was split into two parts