de.caff.util.debug

## Class Format

- java.lang.Object
- - de.caff.util.debug.Format

-     public class Format
      extends java.lang.Object

  Simple class for parsing format strings similar to the C printf functionality.

  The places in the format strings where the arguments will be inserted are marked with `%1` to `%9` thus allowing reordering. Arguments must be objects, primitive types are not allowed. If needed, primitive bytes must be boxed by their standard wrappers.

  Author:
    Rammi

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Format()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `center(java.lang.String str, int length, java.lang.String fill)` Produce a string where `str` is centered.
    `static java.lang.String` | `format(java.lang.Object mask, java.lang.Object... args)` Parses a format string with arguments marked by `%0` to `%9` (max.) and substitutes in the arguments accordingly.
    `static int` | `getMaxStringLength(java.lang.String[] strings)` Get the length of the longest string in a set of strings.
    `static java.lang.String` | `lpad(java.lang.String str, int length, java.lang.String fill)` Left pads the given string with the fill until `length` characters are reached.
    `static void` | `main(java.lang.String[] args)` Test routines.
    `static java.lang.String` | `replace(java.lang.String str1, java.lang.String str2, java.lang.String str3)` Replaces all occurencies of `str2` in `str1` by `str3`
    `static java.lang.String` | `rpad(java.lang.String str, int length, java.lang.String fill)` Right pads the given string with the fill until `length` is reached.
    `static java.lang.String` | `toString(java.lang.Object obj)` Make a string from objects.
    `static java.lang.String` | `trimLeft(java.lang.String str)` Trims the left side of a string.
    `static java.lang.String` | `trimRight(java.lang.String str)` Trims the right side of a string.

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

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

- - ### Constructor Detail

    - #### Format

          public Format()

  - ### Method Detail

    - #### format

          public static java.lang.String format(@NotNull
                                                java.lang.Object mask,
                                                java.lang.Object... args)

      Parses a format string with arguments marked by `%0` to `%9` (max.) and substitutes in the arguments accordingly.
      Parameters:
        `mask` - format string
        `args` - further arguments (minimal length needed is as much as the highest digit used in the markers)
      Returns:
        formatted string

    - #### toString

          public static java.lang.String toString(@Nullable
                                                  java.lang.Object obj)

      Make a string from objects.

      Handles arrays specially.

      Parameters:
        `obj` - object
      Returns:
        string representation

    - #### getMaxStringLength

          public static int getMaxStringLength(@NotNull
                                               java.lang.String[] strings)

      Get the length of the longest string in a set of strings.
      Parameters:
        `strings` - the set of strings as an array
      Returns:
        the maximum length

    - #### rpad

          public static java.lang.String rpad(@NotNull
                                              java.lang.String str,
                                              int length,
                                              @NotNull
                                              java.lang.String fill)

      Right pads the given string with the fill until `length` is reached.
      Parameters:
        `str` - the string to be right padded
        `length` - the length when the padding stops
        `fill` - the string with which `str` is padded
      Returns:
        the padded string cut to `length` chars

    - #### lpad

          public static java.lang.String lpad(@NotNull
                                              java.lang.String str,
                                              int length,
                                              @NotNull
                                              java.lang.String fill)

      Left pads the given string with the fill until `length` characters are reached.
      Parameters:
        `str` - the string to be left padded
        `length` - the length when the padding stops
        `fill` - the string with which `str` is padded
      Returns:
        the padded string cut to `length` chars

    - #### center

          public static java.lang.String center(@NotNull
                                                java.lang.String str,
                                                int length,
                                                @NotNull
                                                java.lang.String fill)

      Produce a string where `str` is centered. `str` is left padded with fill.
      Parameters:
        `str` - the string to be centered
        `length` - the length where `str` is centered
        `fill` - the string with which `str` is padded
      Returns:
        the centered string cut to `length` chars

    - #### replace

          public static java.lang.String replace(@NotNull
                                                 java.lang.String str1,
                                                 @NotNull
                                                 java.lang.String str2,
                                                 @NotNull
                                                 java.lang.String str3)

      Replaces all occurencies of `str2` in `str1` by `str3`
      Parameters:
        `str1` - in this string substrings will be replaced, must be != null
        `str2` - string to be replaced, must be != null and != ""
        `str3` - string to replace, must be != null
      Returns:
        the resulting string

    - #### trimLeft

          public static java.lang.String trimLeft(@Nullable
                                                  java.lang.String str)

      Trims the left side of a string. I.e. takes away all white space and control characters from the left.
      Parameters:
        `str` - string to trim
      Returns:
        trimmed string

    - #### trimRight

          public static java.lang.String trimRight(@Nullable
                                                   java.lang.String str)

      Trims the right side of a string. I.e. takes away all white space and control characters from the right.
      Parameters:
        `str` - string to trim
      Returns:
        trimmed string

    - #### main

          public static void main(java.lang.String[] args)

      Test routines.
      Parameters:
        `args` - unused