Package org.jtrim2.concurrent.query
Class AsyncFormatHelper
java.lang.Object
org.jtrim2.concurrent.query.AsyncFormatHelper
Contains static helper methods to create consistent string format for
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.
Thread safety
Methods of this class are safe to be used by multiple threads concurrently.Synchronization transparency
Methods of this class are synchronization transparent unless otherwise noted.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendIndented(Object obj, StringBuilder result) Appends the object converted to a string (by calling itsObject.toString()method) after indenting it to the specifiedStringBuilder.static voidappendIndented(String text, StringBuilder result) Appends the given string after indenting it to the specifiedStringBuilder.static StringarrayToString(Object[] array) Converts the specified array to a string.static StringcollectionToString(Collection<?> elements) Converts the specifiedCollectionto a string.static StringindentText(String text, boolean indentFirstLine) Adds an indentation before every line (optionally the first line can be an exception) of the given string.static booleanisSingleLine(String text) Checks whether the specified text contains only a single line.static StringtoIndentedString(Object obj, boolean indentFirstLine) Converts the specified object to string (using itstoStringmethod) and returns this string after applying an indentation.
-
Method Details
-
indentText
Adds an indentation before every line (optionally the first line can be an exception) of the given string. The line separator is the'\n'character (UNICODE: 000A).The indentation is currently two space characters.
- Parameters:
text- the possibly multi line text which is to be indented. This argument can benull, in which case the string"null"is used for this argument.indentFirstLine-trueif the first line of the specified text must be indented,falseif the first line must not be indented- Returns:
- the specified text after the applied indentation. This method
never returns
null(not even if the specified text wasnull). - See Also:
-
toIndentedString
Converts the specified object to string (using itstoStringmethod) and returns this string after applying an indentation. The indentation is done the same way as done by theindentText(String, boolean)method.- Parameters:
obj- the object to be converted to string and to be indented. This argument can benull, in which case its string representation is assumed to benull(and therefore the string"null"will be used).indentFirstLine-trueif the first line of the specified text must be indented,falseif the first line must not be indented- Returns:
- the string representation of the specified object after the
applied indentation. This method never returns
null(not even if the specified object wasnullor its string representation wasnull). - See Also:
-
isSingleLine
Checks whether the specified text contains only a single line. That is, returnstrueif the specified text isnullor does not contain the'\n'character (UNICODE: 000A).- Parameters:
text- the text to be checked if it contains multiple lines or not. This argument can benulland in this case it is assumed to be a single line text.- Returns:
trueif the line does not contain multiple lines,falseotherwise
-
appendIndented
Appends the given string after indenting it to the specifiedStringBuilder.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).- Parameters:
text- the text to be appended to the specifiedStringBuilderafter indenting it. This argument can benullin which case the string "null" is appended (without indentation).result- theStringBuilderto which the string is to be appended. This argument cannot benull.- Throws:
NullPointerException- thrown if the specifiedStringBuilderisnull- See Also:
-
appendIndented
Appends the object converted to a string (by calling itsObject.toString()method) after indenting it to the specifiedStringBuilder. If the object isnull, its string representation is assumed to benull. This method is apart from the need to call thetoStringmethod is identical toIf 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).- Parameters:
obj- the object to be converted to string and then appended to the specifiedStringBuilderafter indenting it. This argument can benullin which case the string "null" is appended (without indentation).result- theStringBuilderto which the string representation of the specified object is to be appended. This argument cannot benull.- Throws:
NullPointerException- thrown if the specifiedStringBuilderisnull
-
arrayToString
Converts the specified array to a string. This methods works similar to thejava.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.- Parameters:
array- the array to be converted to string. This argument can benull, in which case the string "null" is returned.- Returns:
- the string representation of the passed array. This method never
returns
null. - See Also:
-
collectionToString
Converts the specifiedCollectionto a string. This method works exactly the same as thearrayToString(Object[])method but for collections rather than array. The order of the elements depends on the order the iterator of the collection returns them.- Parameters:
elements- the collection to be converted to a string. This argument can benull, in which case the string "null" is returned.- Returns:
- the string representation of the passed collection. This method
never returns
null. - See Also:
-