Top Description Inners Constructors Methods
org.assertj.core.util

public final Class Strings

extends Object
Class Inheritance
Static Imports
java.lang.String.format, java.util.Arrays.stream, java.util.stream.Collectors.joining, org.assertj.core.util.Preconditions.checkArgument

Utility methods related to Strings.
Author
Alex Ruiz

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Strings.StringsToJoin

Knows how to join Strings using a given delimiter.

public static class
Strings.StringToAppend

Knows how to append a given String to the given target, only if the target does not end with the given String to append.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Strings.StringToAppend

Returns:

an intermediate object that takes the target String and knows to append the given String.
append
(String
the String to append.
toAppend
)

Appends a given String to the given target, only if the target does not end with the given String to append.

public static String

Returns:

a String containing the given objects.
concat
(Object...
the objects to concatenate.
objects
)

Concatenates the given objects into a single String.

public static String

Returns:

the escaped String
escapePercent
(String
the String to escape
value
)

Escape any % to %% to avoid interpreting it in String#format(String, Object...).

private static String
public static String

Returns:

the formatted string if any args were given
formatIfArgs
(String
the string to format
message
,
Object...
args used to format the message, can be null or empty
args
)

Format with String#format(String, Object...) the given message if some args have been given otherwise just return the message.

public static boolean

Returns:

true if the given String is null or empty, otherwise false.
isNullOrEmpty
(String
the String to check.
s
)

Indicates whether the given String is null or empty.

public static Strings.StringsToJoin

Returns:

an intermediate object that takes a given delimiter and knows how to join the given Strings.
join
(String...
the Strings to join.
strings
)

Joins the given Strings using a given delimiter.

public static Strings.StringsToJoin

Returns:

an intermediate object that takes a given delimiter and knows how to join the given Objects.
join
(Iterable<?>
the Objects to join.
toStringable
)

Joins the given Objects using a given delimiter.

public static String

Returns:

the given String surrounded by single quotes, or null if the given String is null.
quote
(String
the given String.
s
)

Returns the given String surrounded by single quotes, or null if the given String is null.

public static Object

Returns:

the given object surrounded by single quotes, only if the object is a String.
quote
(Object
the given object.
o
)

Returns the given object surrounded by single quotes, only if the object is a String.

private static String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Stringsback to summary
private Strings()

Method Detail

appendback to summary
public static Strings.StringToAppend append(String toAppend)

Appends a given String to the given target, only if the target does not end with the given String to append. The following example illustrates proper usage of this method:

 Strings.append("c").to("ab");
Strings.append("c").to("abc");
resulting in the String "abc" for both cases.
Parameters
toAppend:String

the String to append.

Returns:Strings.StringToAppend

an intermediate object that takes the target String and knows to append the given String.

See Also
StringToAppend#to(String)
concatback to summary
public static String concat(Object... objects)

Concatenates the given objects into a single String. This method is more efficient than concatenating using "+", since only one StringBuilder is created.

Parameters
objects:Object[]

the objects to concatenate.

Returns:String

a String containing the given objects.

escapePercentback to summary
public static String escapePercent(String value)

Escape any % to %% to avoid interpreting it in String#format(String, Object...).

Parameters
value:String

the String to escape

Returns:String

the escaped String

escapePercentExceptWhenFollowedBy_nback to summary
private static String escapePercentExceptWhenFollowedBy_n(String message)
formatIfArgsback to summary
public static String formatIfArgs(String message, Object... args)

Format with String#format(String, Object...) the given message if some args have been given otherwise just return the message.

Parameters
message:String

the string to format

args:Object[]

args used to format the message, can be null or empty

Returns:String

the formatted string if any args were given

isNullOrEmptyback to summary
public static boolean isNullOrEmpty(String s)

Indicates whether the given String is null or empty.

Parameters
s:String

the String to check.

Returns:boolean

true if the given String is null or empty, otherwise false.

joinback to summary
public static Strings.StringsToJoin join(String... strings)

Joins the given Strings using a given delimiter. The following example illustrates proper usage of this method:

 Strings.join("a", "b", "c").with("|");
which will result in the String "a|b|c".
Parameters
strings:String[]

the Strings to join.

Returns:Strings.StringsToJoin

an intermediate object that takes a given delimiter and knows how to join the given Strings.

See Also
StringsToJoin#with(String)
joinback to summary
public static Strings.StringsToJoin join(Iterable<?> toStringable)

Joins the given Objects using a given delimiter. The following example illustrates proper usage of this method:

 Strings.join(new ArrayList("a", "b", "c")).with("|");
which will result in the String "a|b|c".
Parameters
toStringable:Iterable<?>

the Objects to join.

Returns:Strings.StringsToJoin

an intermediate object that takes a given delimiter and knows how to join the given Objects.

See Also
StringsToJoin#with(String)
quoteback to summary
public static String quote(String s)

Returns the given String surrounded by single quotes, or null if the given String is null.

Parameters
s:String

the given String.

Returns:String

the given String surrounded by single quotes, or null if the given String is null.

quoteback to summary
public static Object quote(Object o)

Returns the given object surrounded by single quotes, only if the object is a String.

Parameters
o:Object

the given object.

Returns:Object

the given object surrounded by single quotes, only if the object is a String.

See Also
quote(String)
revertEscapingPercent_nback to summary
private static String revertEscapingPercent_n(String value)
org.assertj.core.util back to summary

public Class Strings.StringsToJoin

extends Object
Class Inheritance

Knows how to join Strings using a given delimiter.
See Also
Strings#join(String[])

Field Summary

Modifier and TypeField and Description
private final String[]
strings

The Strings to join.

Constructor Summary

AccessConstructor and Description
pack-priv
StringsToJoin(String...
the Strings to join.
strings
)

Creates a new StringsToJoin.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the Strings joined using the given delimiter.
with
(String
the delimiter to use.
delimiter
)

Specifies the delimiter to use to join Strings.

public String

Returns:

the Strings joined using the given delimiter.
with
(String
the delimiter to use.
delimiter
,
String
the String wrapper to use.
escapeString
)

Specifies the delimiter to use to join Strings and the escape String to wrap strings with.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

stringsback to summary
private final String[] strings

The Strings to join.

Constructor Detail

StringsToJoinback to summary
pack-priv StringsToJoin(String... strings)

Creates a new StringsToJoin.

Parameters
strings:String[]

the Strings to join.

Method Detail

withback to summary
public String with(String delimiter)

Specifies the delimiter to use to join Strings.

Parameters
delimiter:String

the delimiter to use.

Returns:String

the Strings joined using the given delimiter.

withback to summary
public String with(String delimiter, String escapeString)

Specifies the delimiter to use to join Strings and the escape String to wrap strings with.

Parameters
delimiter:String

the delimiter to use.

escapeString:String

the String wrapper to use.

Returns:String

the Strings joined using the given delimiter.

org.assertj.core.util back to summary

public Class Strings.StringToAppend

extends Object
Class Inheritance

Knows how to append a given String to the given target, only if the target does not end with the given String to append.

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

a String containing the target String with the given String to append added to the end.
to
(String
the target String.
s
)

Appends the String specified in the constructor to the String passed as argument.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

toAppendback to summary
private final String toAppend

Constructor Detail

StringToAppendback to summary
pack-priv StringToAppend(String toAppend)

Method Detail

toback to summary
public String to(String s)

Appends the String specified in the constructor to the String passed as argument.

Parameters
s:String

the target String.

Returns:String

a String containing the target String with the given String to append added to the end.