Package org.assertj.core.util
Class Strings
- java.lang.Object
-
- org.assertj.core.util.Strings
-
public final class Strings extends java.lang.ObjectUtility methods related toStrings.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStrings.StringsToJoinKnows how to joinStrings using a given delimiter.static classStrings.StringToAppendKnows how to append a givenStringto the given target, only if the target does not end with the givenStringto append.
-
Constructor Summary
Constructors Modifier Constructor Description privateStrings()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Strings.StringToAppendappend(java.lang.String toAppend)Appends a givenStringto the given target, only if the target does not end with the givenStringto append.static java.lang.Stringconcat(java.lang.Object... objects)Concatenates the given objects into a singleString.static java.lang.StringescapePercent(java.lang.String value)Escape any%to%%to avoid interpreting it inString.format(String, Object...).private static java.lang.StringescapePercentExceptWhenFollowedBy_n(java.lang.String message)static java.lang.StringformatIfArgs(java.lang.String message, java.lang.Object... args)Format withString.format(String, Object...)the given message if some args have been given otherwise just return the message.static booleanisNullOrEmpty(java.lang.String s)Indicates whether the givenStringisnullor empty.static Strings.StringsToJoinjoin(java.lang.Iterable<?> toStringable)Joins the givenObjects using a given delimiter.static Strings.StringsToJoinjoin(java.lang.String... strings)Joins the givenStrings using a given delimiter.static java.lang.Objectquote(java.lang.Object o)Returns the given object surrounded by single quotes, only if the object is aString.static java.lang.Stringquote(java.lang.String s)Returns the givenStringsurrounded by single quotes, ornullif the givenStringisnull.private static java.lang.StringrevertEscapingPercent_n(java.lang.String value)
-
-
-
Method Detail
-
isNullOrEmpty
public static boolean isNullOrEmpty(java.lang.String s)
Indicates whether the givenStringisnullor empty.- Parameters:
s- theStringto check.- Returns:
trueif the givenStringisnullor empty, otherwisefalse.
-
quote
public static java.lang.String quote(java.lang.String s)
Returns the givenStringsurrounded by single quotes, ornullif the givenStringisnull.- Parameters:
s- the givenString.- Returns:
- the given
Stringsurrounded by single quotes, ornullif the givenStringisnull.
-
quote
public static java.lang.Object quote(java.lang.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 java.lang.String concat(java.lang.Object... objects)
Concatenates the given objects into a singleString. This method is more efficient than concatenating using "+", since only oneis created.StringBuilder- Parameters:
objects- the objects to concatenate.- Returns:
- a
Stringcontaining the given objects.
-
formatIfArgs
public static java.lang.String formatIfArgs(java.lang.String message, java.lang.Object... args)Format withString.format(String, Object...)the given message if some args have been given otherwise just 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 java.lang.String escapePercent(java.lang.String value)
Escape any%to%%to avoid interpreting it inString.format(String, Object...).- Parameters:
value- the String to escape- Returns:
- the escaped String
-
join
public static Strings.StringsToJoin join(java.lang.String... strings)
Joins the givenStrings 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- theStrings to join.- Returns:
- an intermediate object that takes a given delimiter and knows how to join the given
Strings. - See Also:
Strings.StringsToJoin.with(String)
-
join
public static Strings.StringsToJoin join(java.lang.Iterable<?> toStringable)
Joins the givenObjects 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- theObjects to join.- Returns:
- an intermediate object that takes a given delimiter and knows how to join the given
Objects. - See Also:
Strings.StringsToJoin.with(String)
-
append
public static Strings.StringToAppend append(java.lang.String toAppend)
Appends a givenStringto the given target, only if the target does not end with the givenStringto 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- theStringto append.- Returns:
- an intermediate object that takes the target
Stringand knows to append the givenString. - See Also:
Strings.StringToAppend.to(String)
-
escapePercentExceptWhenFollowedBy_n
private static java.lang.String escapePercentExceptWhenFollowedBy_n(java.lang.String message)
-
revertEscapingPercent_n
private static java.lang.String revertEscapingPercent_n(java.lang.String value)
-
-