- java.lang.Object
-
- de.carne.util.Strings
-
public final class Strings extends java.lang.ObjectUtility class providing String related functions.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringELLIPSISEllipsis string.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringdecode(java.lang.CharSequence chars)Decodes a CharSequence previously encoded via encode(CharSequence).static java.lang.Stringencode(java.lang.CharSequence chars)Encodes a CharSequence to a pure ASCII representation by quoting non printable characters.static java.lang.StringBuilderencode(java.lang.StringBuilder buffer, java.lang.CharSequence chars)Encodes a CharSequence to a pure ASCII representation by quoting non printable characters.static java.lang.StringencodeHtml(java.lang.CharSequence chars)Encodes a CharSequence to a HTML conform representation by quoting special characters.static java.lang.StringBuilderencodeHtml(java.lang.StringBuilder buffer, java.lang.CharSequence chars)Encodes a CharSequence to a HTML conform representation by quoting special characters.static booleanisEmpty(@Nullable java.lang.String s)Checks whether a String is empty.static java.lang.Stringjoin(java.lang.Iterable<?> objects, java.lang.String delim)Joins the String representation of multiple Objects into a single String.static java.lang.Stringjoin(java.lang.Iterable<?> objects, java.lang.String delim, int limit)Joins the String representation of multiple Objects into a single String.static java.lang.Stringjoin(java.lang.Iterable<?> objects, java.lang.String delim, int limit, java.lang.String ellipsis)Joins the String representation of multiple Objects into a single String.static java.lang.Stringjoin(java.lang.Object[] objects, java.lang.String delim)Joins the String representation of multiple Objects into a single String.static java.lang.Stringjoin(java.lang.Object[] objects, java.lang.String delim, int limit)Joins the String representation of multiple Objects into a single String.static java.lang.Stringjoin(java.lang.Object[] objects, java.lang.String delim, int limit, java.lang.String ellipsis)Joins the String representation of multiple Objects into a single String.static booleannotEmpty(@Nullable java.lang.String s)Checks whether a String is not empty.static java.lang.Stringsafe(@Nullable java.lang.String s)Makes sure a String is notnull.static java.lang.StringsafeTrim(@Nullable java.lang.String s)Makes sure a String is notnulland trimmed.static @NonNull java.lang.String[]split(java.lang.String s, char delim, boolean all)Splits a String according to a given delimiter.static @Nullable java.lang.Stringtrim(@Nullable java.lang.String s)Makes sure a String is eithernullor trimmed.static java.lang.StringvalueOf(@Nullable java.lang.Object o)Gets the string representation of the submitted object and never returnsnull.
-
-
-
Method Detail
-
isEmpty
public static boolean isEmpty(@Nullable java.lang.String s)
Checks whether a String is empty.A String is considered empty if it is either
nullor of length0.- Parameters:
s- the String to check.- Returns:
trueif the string is empty.
-
notEmpty
public static boolean notEmpty(@Nullable java.lang.String s)
Checks whether a String is not empty.A String is considered empty if it is either
nullor of length0.- Parameters:
s- the String to check.- Returns:
trueif the string is not empty.
-
valueOf
public static java.lang.String valueOf(@Nullable java.lang.Object o)
Gets the string representation of the submitted object and never returnsnull.- Parameters:
o- the object to get the string representation of.- Returns:
- the string representation of the submitted object (never
null).
-
safe
public static java.lang.String safe(@Nullable java.lang.String s)
Makes sure a String is notnull.- Parameters:
s- the String to check.- Returns:
- the submitted String or
""ifnullwas submitted.
-
safeTrim
public static java.lang.String safeTrim(@Nullable java.lang.String s)
Makes sure a String is notnulland trimmed.- Parameters:
s- the String to trim.- Returns:
- the submitted String in trimmed form or
""ifnullwas submitted.
-
trim
public static @Nullable java.lang.String trim(@Nullable java.lang.String s)
Makes sure a String is eithernullor trimmed.- Parameters:
s- the String to trim.- Returns:
- the submitted String in trimmed form or
nullifnullwas submitted.
-
split
public static @NonNull java.lang.String[] split(java.lang.String s, char delim, boolean all)Splits a String according to a given delimiter.- Parameters:
s- the String to split.delim- the delimiter character to split at.all- whether to split at all occurrences of the delimiter character (true) or only at the first one (false).- Returns:
- the splitted sub-strings. The actual number of sub-strings depends on the actual occurrences of the
delimiter character as well as the
allflag.
-
join
public static java.lang.String join(java.lang.Object[] objects, java.lang.String delim)Joins the String representation of multiple Objects into a single String.The Object.toString() is used to retrieve the Objects' String representation.
- Parameters:
objects- the Objectss to join.delim- the delimiter to use for joining.- Returns:
- the joined String.
-
join
public static java.lang.String join(java.lang.Iterable<?> objects, java.lang.String delim)Joins the String representation of multiple Objects into a single String.The Object.toString() is used to retrieve the Objects' String representation.
- Parameters:
objects- the Objectss to join.delim- the delimiter to use for joining.- Returns:
- the joined String.
-
join
public static java.lang.String join(java.lang.Object[] objects, java.lang.String delim, int limit)Joins the String representation of multiple Objects into a single String.The Object.toString() is used to retrieve the Objects' String representation.
- Parameters:
objects- the Strings to join.delim- the delimiter to use for joining.limit- the maximum length of the joined String.- Returns:
- the joined String.
-
join
public static java.lang.String join(java.lang.Iterable<?> objects, java.lang.String delim, int limit)Joins the String representation of multiple Objects into a single String.The Object.toString() is used to retrieve the Objects' String representation.
- Parameters:
objects- the Strings to join.delim- the delimiter to use for joining.limit- the maximum length of the joined String.- Returns:
- the joined String.
-
join
public static java.lang.String join(java.lang.Object[] objects, java.lang.String delim, int limit, java.lang.String ellipsis)Joins the String representation of multiple Objects into a single String.The Object.toString() is used to retrieve the Objects' String representation.
- Parameters:
objects- the Objectss to join.delim- the delimiter to use for joining.limit- the maximum length of the joined String.ellipsis- the ellipsis to place at the end of the joined string in caselimitis reached.- Returns:
- the joined String.
-
join
public static java.lang.String join(java.lang.Iterable<?> objects, java.lang.String delim, int limit, java.lang.String ellipsis)Joins the String representation of multiple Objects into a single String.The Object.toString() is used to retrieve the Objects' String representation.
- Parameters:
objects- the Objectss to join.delim- the delimiter to use for joining.limit- the maximum length of the joined String.ellipsis- the ellipsis to place at the end of the joined string in caselimitis reached.- Returns:
- the joined String.
-
encode
public static java.lang.String encode(java.lang.CharSequence chars)
Encodes a CharSequence to a pure ASCII representation by quoting non printable characters.- Parameters:
chars- the CharSequence to encode.- Returns:
- the encoded characters.
-
encode
public static java.lang.StringBuilder encode(java.lang.StringBuilder buffer, java.lang.CharSequence chars)Encodes a CharSequence to a pure ASCII representation by quoting non printable characters.- Parameters:
buffer- the StringBuilder to encode into.chars- the CharSequence to encode.- Returns:
- the encoded characters.
-
decode
public static java.lang.String decode(java.lang.CharSequence chars)
Decodes a CharSequence previously encoded via encode(CharSequence).- Parameters:
chars- the CharSequence to decode.- Returns:
- the decoded characters.
-
encodeHtml
public static java.lang.String encodeHtml(java.lang.CharSequence chars)
Encodes a CharSequence to a HTML conform representation by quoting special characters.- Parameters:
chars- the CharSequence to encode.- Returns:
- the encoded characters.
-
encodeHtml
public static java.lang.StringBuilder encodeHtml(java.lang.StringBuilder buffer, java.lang.CharSequence chars)Encodes a CharSequence to a HTML conform representation by quoting special characters.- Parameters:
buffer- the StringBuilder to encode into.chars- the CharSequence to encode.- Returns:
- the encoded characters.
-
-