net.returnvoid.tools

## Class StringTools

- java.lang.Object
- - net.returnvoid.tools.StringTools

-     public class StringTools
      extends java.lang.Object

  A collection of functions to format Strings or to parse other data types to String in a certain way.
  Author:
    Diana Lange

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `getKeyValue(java.lang.String key, java.util.ArrayList<java.lang.String> values)` Will maybe be moved to StringTools.
    `static java.lang.String` | `getKeyValue(java.lang.String key, java.lang.String value)` Will maybe be moved to StringTools.
    `static java.lang.String` | `getKeyValue(java.lang.String key, java.lang.String value, boolean escapeValue)` Will maybe be moved to StringTools.
    `static java.lang.String` | `getStringEcp(java.lang.String txt)` Will maybe be moved to StringTools.
    `static java.lang.String` | `join(java.util.ArrayList<java.lang.String> list, java.lang.String separator)` Joins a list of elements to one single String.
    `static java.lang.String` | `join(float[] list, java.lang.String separator)` Joins a list of elements to one single String.
    `static java.lang.String` | `join(int[] list, java.lang.String separator)` Joins a list of elements to one single String.
    `static java.lang.String` | `join(java.lang.Object[] list, java.lang.String separator)` Joins a list of elements to one single String.
    `static java.lang.String` | `join(java.lang.String separator, java.lang.Object... elements)` Joins a list of elements to one single String.
    `static java.lang.String` | `joinAndFormat(float[] list, java.lang.String separator, int d1, int d2)` Joins a list of elements to one single String.
    `static java.lang.String` | `joinAndFormat(int[] list, java.lang.String separator, int digits)` Joins a list of elements to one single String.
    `static java.lang.String` | `nf(int val, int digits)` Parses the given int to a String.
    `static java.lang.String` | `nfs(float val, int d1, int d2)` Parses the given value to a String.
    `static java.lang.String` | `timestamp()` Returns a String containing the current time (yyyymmdd_hhmmss).

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### timestamp

          public static java.lang.String timestamp()

      Returns a String containing the current time (yyyymmdd_hhmmss).
      Returns:
        The timestamp.

    - #### nf

          public static java.lang.String nf(int val,
                                            int digits)

      Parses the given int to a String. The output String will contain digits numbers and a sign. Empty spaces will be filled with zeroes and too many numbers will be cut. Example:

           StringTools.nf(3, 4); // "+0003"
           StringTools.nf(-1999, 3); // "-999"

      Parameters:
        `val` - The number that should be parsed.
        `digits` - The number of numbers that should be in the output String.
      Returns:
        The parsed and formated String.

    - #### nfs

          public static java.lang.String nfs(float val,
                                             int d1,
                                             int d2)

      Parses the given value to a String. The output String will contain d1 numbers before the point separator, d2 numbers after the point separator and a sign. Empty spaces will be filled with zeroes and too many numbers will be cut. Example:

           StringTools.nfs(3.5, 2, 2); // "+03.50"
           StringTools.nfs(-1999, 3, 2); // "-999.00"

      Parameters:
        `val` - The number that should be parsed.
        `d1` - The number of numbers before the point.
        `d2` - The number of numbers after the point.
      Returns:
        The parsed and formated String.

    - #### join

          public static java.lang.String join(float[] list,
                                              java.lang.String separator)

      Joins a list of elements to one single String. The elements of the list will be separated by separator.
      Parameters:
        `list` - A float array which should be joined.
        `separator` - A String which will be used to separate the elements of the input list.
      Returns:
        The joined String.

    - #### join

          public static java.lang.String join(int[] list,
                                              java.lang.String separator)

      Joins a list of elements to one single String. The elements of the list will be separated by separator.
      Parameters:
        `list` - A float array which should be joined.
        `separator` - A String which will be used to separate the elements of the input list.
      Returns:
        The joined String.

    - #### join

          public static java.lang.String join(java.lang.String separator,
                                              java.lang.Object... elements)

      Joins a list of elements to one single String. The elements of the list will be separated by separator.
      Parameters:
        `separator` - A String which will be used to separate the elements of the input list.
        `elements` - One or more elements that should be joined.
      Returns:
        The joined String.

    - #### join

          public static java.lang.String join(java.lang.Object[] list,
                                              java.lang.String separator)

      Joins a list of elements to one single String. The elements of the list will be separated by separator.
      Parameters:
        `list` - A float array which should be joined.
        `separator` - A String which will be used to separate the elements of the input list.
      Returns:
        The joined String.

    - #### join

          public static java.lang.String join(java.util.ArrayList<java.lang.String> list,
                                              java.lang.String separator)

      Joins a list of elements to one single String. The elements of the list will be separated by separator.
      Parameters:
        `list` - A float array which should be joined.
        `separator` - A String which will be used to separate the elements of the input list.
      Returns:
        The joined String.

    - #### joinAndFormat

          public static java.lang.String joinAndFormat(float[] list,
                                                       java.lang.String separator,
                                                       int d1,
                                                       int d2)

      Joins a list of elements to one single String. The elements of the list will be separated by separator. The elements of the list will be parsed to a String. This String will contain d1 numbers before the point separator, d2 numbers after the point separator and a sign. Empty spaces will be filled with zeroes and too many numbers will be cut. Example:

           float[] vals = { 3.4, -267.45, -23.246 };
           StringTools.joinAndFormat(vals, ",", 2, 2); // "+03.40,-67.45,-23.24"

      Parameters:
        `list` - A float array which should be joined.
        `separator` - A String which will be used to separate the elements of the input list.
        `d1` - The number of numbers before the point.
        `d2` - The number of numbers after the point.
      Returns:
        The joined String.

    - #### joinAndFormat

          public static java.lang.String joinAndFormat(int[] list,
                                                       java.lang.String separator,
                                                       int digits)

      Joins a list of elements to one single String. The elements of the list will be separated by separator. The elements of the list will be parsed to a String. This String will contain digits numbers and a sign. Empty spaces will be filled with zeroes and too many numbers will be cut. Example:

           int[] vals = { 3, 1999, -23 };
           StringTools.joinAndFormat(vals, ",", 3); // "+003,+999,-023"

      Parameters:
        `list` - A float array which should be joined.
        `separator` - A String which will be used to separate the elements of the input list.
        `digits` - The number of numbers for each list element.
      Returns:
        The joined String.

    - #### getStringEcp

          public static java.lang.String getStringEcp(java.lang.String txt)

      Will maybe be moved to StringTools. Puts escaped quotations marks around the input. Used for creating Strings representing JSON Objects.
      Parameters:
        `txt` - The input text.
      Returns:
        The input text with added quotations marks.

    - #### getKeyValue

          public static java.lang.String getKeyValue(java.lang.String key,
                                                     java.util.ArrayList<java.lang.String> values)

      Will maybe be moved to StringTools. Creates an escaped key-array value pair (e.g. \"key\" : [\"val1\", \"val2\"]). Used for creating Strings representing JSON Objects.
      Parameters:
        `key` - The key of the key-value pair.
        `values` - A list of String values.
      Returns:
        A string containing the escaped key-array value pair.

    - #### getKeyValue

          public static java.lang.String getKeyValue(java.lang.String key,
                                                     java.lang.String value,
                                                     boolean escapeValue)

      Will maybe be moved to StringTools. Creates an escaped key-array value pair (e.g. \"key\" : \"val\"). Used for creating Strings representing JSON Objects.
      Parameters:
        `key` - The key of the key-value pair.
        `value` - The value of the key-value pair.
        `escapeValue` - Defines if the value part should be escaped. Should be false, if the value is already escaped or the value is a pre-formated array-string.
      Returns:
        A string containing the escaped key-value pair.

    - #### getKeyValue

          public static java.lang.String getKeyValue(java.lang.String key,
                                                     java.lang.String value)

      Will maybe be moved to StringTools. Creates an escaped key-array value pair (e.g. \"key\" : \"val\"). Used for creating Strings representing JSON Objects.
      Parameters:
        `key` - The key of the key-value pair.
        `value` - The value of the key-value pair.
      Returns:
        A string containing the escaped key-value pair.