Class AsyncFormatHelper

java.lang.Object
org.jtrim2.concurrent.query.AsyncFormatHelper

public final class AsyncFormatHelper extends Object
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 Details

    • indentText

      public 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. 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 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 indented
      Returns:
      the specified text after the applied indentation. This method never returns null (not even if the specified text was null).
      See Also:
    • toIndentedString

      public 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. The indentation is done the same way as done by the indentText(String, boolean) method.
      Parameters:
      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 indented
      Returns:
      the string representation of the specified object after the applied indentation. This method never returns null (not even if the specified object was null or its string representation was null).
      See Also:
    • isSingleLine

      public static boolean isSingleLine(String text)
      Checks whether the specified text contains only a single line. That is, returns true if the specified text is null or 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 be null and in this case it is assumed to be a single line text.
      Returns:
      true if the line does not contain multiple lines, false otherwise
    • appendIndented

      public static void appendIndented(String text, StringBuilder result)
      Appends the given string after indenting it to the specified 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).

      Parameters:
      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.
      Throws:
      NullPointerException - thrown if the specified StringBuilder is null
      See Also:
    • appendIndented

      public 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. 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).

      Parameters:
      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.
      Throws:
      NullPointerException - thrown if the specified StringBuilder is null
    • arrayToString

      public static String arrayToString(Object[] array)
      Converts the specified array to a string. This methods works similar to the 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.
      Parameters:
      array - the array to be converted to string. This argument can be null, in which case the string "null" is returned.
      Returns:
      the string representation of the passed array. This method never returns null.
      See Also:
    • collectionToString

      public static String collectionToString(Collection<?> elements)
      Converts the specified 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.
      Parameters:
      elements - the collection to be converted to a string. This argument can be null, in which case the string "null" is returned.
      Returns:
      the string representation of the passed collection. This method never returns null.
      See Also: