public final class AsyncFormatHelper extends Object
AsyncDataLink and AsyncDataQuery implementations.
Implementations should consider using methods in this class to create a
string representation which looks consistent with the ones in JTrim. The
string formats are not intended to be parsable and therefore the exact result
of the methods of this class may change in future implementations.
This class cannot be inherited or instantiated.
AsyncDataLink,
AsyncDataQuery| Modifier and Type | Method and Description |
|---|---|
static void |
appendIndented(Object obj,
StringBuilder result)
Appends the object converted to a string (by calling its
Object.toString() method) after indenting it to the specified
StringBuilder. |
static void |
appendIndented(String text,
StringBuilder result)
Appends the given string after indenting it to the specified
StringBuilder. |
static String |
arrayToString(Object[] array)
Converts the specified array to a string.
|
static String |
collectionToString(Collection<?> elements)
Converts the specified
Collection to a string. |
static String |
indentText(String text,
boolean indentFirstLine)
Adds an indentation before every line (optionally the first line can be
an exception) of the given string.
|
static boolean |
isSingleLine(String text)
Checks whether the specified text contains only a single line.
|
static String |
toIndentedString(Object obj,
boolean indentFirstLine)
Converts the specified object to string (using its
toString method) and returns this string after
applying an indentation. |
public static String indentText(String text, boolean indentFirstLine)
'\n'
character (UNICODE: 000A).
The indentation is currently two space characters.
text - the possibly multi line text which is to be indented. This
argument can be null, in which case the string "null"
is used for this argument.indentFirstLine - true if the first line of the specified
text must be indented, false if the first line must not be
indentednull (not even if the specified text was
null).toIndentedString(Object, boolean)public static String toIndentedString(Object obj, boolean indentFirstLine)
toString method) and returns this string after
applying an indentation. The indentation is done the same way as done by
the indentText(String, boolean) method.obj - the object to be converted to string and to be indented. This
argument can be null, in which case its string representation
is assumed to be null (and therefore the string "null"
will be used).indentFirstLine - true if the first line of the specified
text must be indented, false if the first line must not be
indentednull (not even
if the specified object was null or its string representation
was null).indentText(String, boolean)public static boolean isSingleLine(String text)
true if the specified text is null or does not
contain the '\n' character (UNICODE: 000A).text - the text to be checked if it contains multiple lines or not.
This argument can be null and in this case it is assumed to be
a single line text.true if the line does not contain multiple lines,
false otherwisepublic static void appendIndented(String text, StringBuilder result)
StringBuilder.
If the passed text contains only a single line,
it will be appended as is without indentation. Otherwise a newline
character ('\n') is appended and the text indented (including its
first line).
text - the text to be appended to the specified
StringBuilder after indenting it. This argument can be
null in which case the string "null" is appended (without
indentation).result - the StringBuilder to which the string is to be
appended. This argument cannot be null.NullPointerException - thrown if the specified
StringBuilder is nullappendIndented(Object, StringBuilder)public static void appendIndented(Object obj, StringBuilder result)
Object.toString() method) after indenting it to the specified
StringBuilder. If the object is null, its string
representation is assumed to be null. This method is apart from
the need to call the toString method is identical to
If the string representation contains only a
single line, it will be appended as is
without indentation. Otherwise a newline character ('\n') is
appended and the text indented (including its first line).
obj - the object to be converted to string and then appended to the
specified StringBuilder after indenting it. This argument can
be null in which case the string "null" is appended (without
indentation).result - the StringBuilder to which the string
representation of the specified object is to be appended. This argument
cannot be null.NullPointerException - thrown if the specified
StringBuilder is nullpublic static String arrayToString(Object[] array)
java.util.Arrays#toString(Object[]) but for arrays having
length of at least 2 returns a multi line string representation where
every element has its own dedicated line. This is intended to be more
readable for larger arrays.array - the array to be converted to string. This argument can be
null, in which case the string "null" is returned.null.collectionToString(Collection)public static String collectionToString(Collection<?> elements)
Collection to a string. This method works
exactly the same as the arrayToString(Object[]) method but
for collections rather than array. The order of the elements depends
on the order the iterator of the collection returns them.elements - the collection to be converted to a string. This argument
can be null, in which case the string "null" is returned.null.arrayToString(Object[])