Package org.assertj.core.util
Class Strings
- java.lang.Object
-
- org.assertj.core.util.Strings
-
public final class Strings extends Object
Utility methods related toString
s.- Author:
- Alex Ruiz
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Strings.StringsToJoin
Knows how to joinString
s using a given delimiter.static class
Strings.StringToAppend
Knows how to append a givenString
to the given target, only if the target does not end with the givenString
to append.
-
Constructor Summary
Constructors Modifier Constructor Description private
Strings()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Strings.StringToAppend
append(String toAppend)
Appends a givenString
to the given target, only if the target does not end with the givenString
to append.static String
concat(Object... objects)
Concatenates the given objects into a singleString
.static String
escapePercent(String value)
private static String
escapePercentExceptWhenFollowedBy_n(String message)
static String
formatIfArgs(String message, Object... args)
Format withString.format(String, Object...)
the given message iif some args have been given otherwise juts return the message.static boolean
isNullOrEmpty(String s)
Indicates whether the givenString
isnull
or empty.static Strings.StringsToJoin
join(Iterable<?> toStringable)
Joins the givenObject
s using a given delimiter.static Strings.StringsToJoin
join(String... strings)
Joins the givenString
s using a given delimiter.static Object
quote(Object o)
Returns the given object surrounded by single quotes, only if the object is aString
.static String
quote(String s)
Returns the givenString
surrounded by single quotes, ornull
if the givenString
isnull
.private static String
revertEscapingPercent_n(String value)
-
-
-
Method Detail
-
isNullOrEmpty
public static boolean isNullOrEmpty(String s)
Indicates whether the givenString
isnull
or empty.- Parameters:
s
- theString
to check.- Returns:
true
if the givenString
isnull
or empty, otherwisefalse
.
-
quote
public static String quote(String s)
Returns the givenString
surrounded by single quotes, ornull
if the givenString
isnull
.- Parameters:
s
- the givenString
.- Returns:
- the given
String
surrounded by single quotes, ornull
if the givenString
isnull
.
-
quote
public static Object quote(Object o)
Returns the given object surrounded by single quotes, only if the object is aString
.- Parameters:
o
- the given object.- Returns:
- the given object surrounded by single quotes, only if the object is a
String
. - See Also:
quote(String)
-
concat
public static String concat(Object... objects)
Concatenates the given objects into a singleString
. This method is more efficient than concatenating using "+", since only one
is created.StringBuilder
- Parameters:
objects
- the objects to concatenate.- Returns:
- a
String
containing the given objects.
-
formatIfArgs
public static String formatIfArgs(String message, Object... args)
Format withString.format(String, Object...)
the given message iif some args have been given otherwise juts return the message.- Parameters:
message
- the string to formatargs
- args used to format the message, can be null or empty- Returns:
- the formatted string if any args were given
-
escapePercent
public static String escapePercent(String value)
- Parameters:
value
- the String to escape- Returns:
- the escaped String
-
join
public static Strings.StringsToJoin join(String... strings)
Joins the givenString
s using a given delimiter. The following example illustrates proper usage of this method:
which will result in theStrings.join("a", "b", "c").with("|");
String
"a|b|c"
.- Parameters:
strings
- theString
s to join.- Returns:
- an intermediate object that takes a given delimiter and knows how to join the given
String
s. - See Also:
Strings.StringsToJoin.with(String)
-
join
public static Strings.StringsToJoin join(Iterable<?> toStringable)
Joins the givenObject
s using a given delimiter. The following example illustrates proper usage of this method:
which will result in theStrings.join(new ArrayList("a", "b", "c")).with("|");
String
"a|b|c"
.- Parameters:
toStringable
- theObject
s to join.- Returns:
- an intermediate object that takes a given delimiter and knows how to join the given
Object
s. - See Also:
Strings.StringsToJoin.with(String)
-
append
public static Strings.StringToAppend append(String toAppend)
Appends a givenString
to the given target, only if the target does not end with the givenString
to append. The following example illustrates proper usage of this method:
resulting in theStrings.append("c").to("ab"); Strings.append("c").to("abc");
String
"abc"
for both cases.- Parameters:
toAppend
- theString
to append.- Returns:
- an intermediate object that takes the target
String
and knows to append the givenString
. - See Also:
Strings.StringToAppend.to(String)
-
escapePercentExceptWhenFollowedBy_n
private static String escapePercentExceptWhenFollowedBy_n(String message)
-
-