de.esprit.common.util

## Class Convert

- java.lang.Object
- - de.esprit.common.util.Convert

-     public class Convert
      extends java.lang.Object

  This is a collection of frequently used conversion utitlity methods
  Author:
    Rainer Buesch

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `colonSep`
    `static long` | `GIGA_BYTE`
    `static long` | `KILO_BYTE`
    `static long` | `MEGA_BYTE`
    `static long` | `TERA_BYTE`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <E> E[]` | `toArrayOfType(java.lang.Class dataType, java.lang.Object[] items)` Creates a never null array of the specified dataType and copies the items into it.
    `static byte[]` | `toAsciiBytes(long value)` Converts the long value into a byte array with ASCII digit characters.
    `static boolean` | `toBoolean(java.lang.Object value)` Converts this Object to a boolean.
    `static boolean` | `toBoolean(java.lang.String value)` Converts the String value to a boolean.
    `static java.lang.String` | `toByteString(long bytes)`
    `static java.lang.String` | `toByteStringUS(long bytes)`
    `static java.util.Collection` | `toCollection(javax.swing.ListModel lm)` Returns the content of the `ListModel` as a `Collection`.
    `static java.awt.Color` | `toColor(java.lang.Object value)` Converts a String to a color object.
    `static DBDate` | `toDate(java.lang.String dateStr)` Creates a `DBDate` object from the given string.
    `static java.lang.String` | `toDecimalString(double number)` Returns a formatted numeric value with a default fraction of 2.
    `static java.lang.String` | `toDecimalString(double number, int fraction)` Returns a formatted numeric value with the given fraction.
    `static java.lang.String` | `toDecimalStringUS(double number, int fraction)`
    `static double` | `toDouble(java.lang.String value)` Converts the string argument to a double value.
    `static java.lang.String` | `toEscapedString(java.lang.String str)` Converts a String such that special characters are quoted with a backslash.
    `static float` | `toFloat(java.lang.String value)` Converts the string argument to a float value.
    `static int` | `toInt(java.lang.Object value)` Converts the argument to an integer.
    `static int` | `toInt(java.lang.String value)` Converts the string argument to an int value.
    `static <E> java.util.List<E>` | `toList(E... values)` Wraps the value object into a List
    `static long` | `toLong(java.lang.Object value)` Silently converts the argument to a long value.
    `static long` | `toLong(java.lang.String value)` Converts the string argument to a long.
    `static short` | `toShort(java.lang.String value)` Converts the string argument to a short value.
    `static java.lang.String` | `toSingleLineString(java.lang.String s)` Replaces all '\n' by blanks
    `static java.lang.String` | `toSqlValueList(java.util.List list)`
    `static java.lang.String` | `toSqlValueList(java.lang.Object[] array)`
    `static java.lang.String` | `toString(java.lang.Object obj)` Converts the argument to a String.
    `static java.lang.String[]` | `toStringArray(java.lang.Object[] args)` Creates a String[] from an object array
    `static java.lang.String[]` | `toStringArray(java.lang.String s)` Creates a String[] from the given String using ',' as the default delimiter
    `static java.lang.String[]` | `toStringArray(java.lang.String str, java.lang.String delim)` Creates a String[] from the given String using the given delimiter
    `static java.lang.String` | `toStringList(java.util.Collection coll)` Converts the collections content to a valueSeparator separated string list.
    `static java.lang.String` | `toStringList(java.util.Collection coll, java.lang.String separator)` Converts the collections content to a list of strings separated by the given separator.
    `static java.lang.String` | `toStringList(java.util.Collection coll, java.lang.String separator, int maxElements)` Converts the collections content to a list of strings separated by the given separator.
    `static java.lang.String` | `toStringList(double[] array)` Converts the array content to a valueSeparator separated string list.
    `static java.lang.String` | `toStringList(double[] array, java.lang.String separator)` Converts the array content to a string list using the given separator for separating the elements.
    `static java.lang.String` | `toStringList(int[] array)` Converts the array content to a valueSeparator separated string list.
    `static java.lang.String` | `toStringList(int[] array, java.lang.String separator)` Converts the array content to a string list using the given separator for separating the elements.
    `static java.lang.String` | `toStringList(java.util.Map map, java.lang.String separator, int maxElements)` Converts the Maps content to a list of strings separated by the given separator.
    `static java.lang.String` | `toStringList(java.lang.Object[] array)` Converts the array content to a valueSeparator separated string list.
    `static java.lang.String` | `toStringList(java.lang.Object[] array, java.lang.String separator)` Converts the array content to a string list using the given separator for separating the elements.
    `static java.lang.String` | `toStringList(java.lang.Object[] array, java.lang.String separator, int maxElements)` Converts the array content to a string list using the given separator for separating the elements.
    `static DBTime` | `toTime(java.lang.String timeStr)` Creates a `DBTime` object from the given string.
    `static DBTimestamp` | `toTimestamp(java.lang.String timestampStr)` Creates a `DBTimestamp` object from the given string.
    `static java.lang.String` | `toUnescapedString(java.lang.String str)` Converts a String such that backslashes are removed from quoted special characters.

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

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

- - ### Field Detail

    - #### KILO_BYTE

          public static final long KILO_BYTE

      See Also:
        Constant Field Values

    - #### MEGA_BYTE

          public static final long MEGA_BYTE

      See Also:
        Constant Field Values

    - #### GIGA_BYTE

          public static final long GIGA_BYTE

      See Also:
        Constant Field Values

    - #### TERA_BYTE

          public static final long TERA_BYTE

      See Also:
        Constant Field Values

    - #### colonSep

          public static final java.lang.String colonSep

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### toColor

          public static java.awt.Color toColor(java.lang.Object value)

      Converts a String to a color object. The String must have the format `R,G,B,A`, where R, G and B are the numeric values for red, green and blue and A is the numeric alpha value. The alpha value is optional.``

    - #### toEscapedString

          public static java.lang.String toEscapedString(java.lang.String str)

      Converts a String such that special characters are quoted with a backslash.

    - #### toUnescapedString

          public static java.lang.String toUnescapedString(java.lang.String str)

      Converts a String such that backslashes are removed from quoted special characters.

    - #### toDecimalString

          public static java.lang.String toDecimalString(double number,
                                         int fraction)

      Returns a formatted numeric value with the given fraction.

    - #### toDecimalStringUS

          public static java.lang.String toDecimalStringUS(double number,
                                           int fraction)

    - #### toDecimalString

          public static java.lang.String toDecimalString(double number)

      Returns a formatted numeric value with a default fraction of 2.

    - #### toBoolean

          public static boolean toBoolean(java.lang.Object value)

      Converts this Object to a boolean. Returns true if it is a Boolean.TRUE or a String representing a boolean value.
      See Also:
        `toBoolean(String)`

    - #### toBoolean

          public static boolean toBoolean(java.lang.String value)

      Converts the String value to a boolean. Returns true if the String starts with a 't' or the numeric '1' character (case insensitive).

    - #### toByteString

          public static java.lang.String toByteString(long bytes)

    - #### toByteStringUS

          public static java.lang.String toByteStringUS(long bytes)

    - #### toLong

          public static long toLong(java.lang.Object value)

      Silently converts the argument to a long value. If the conversion fails, a numeric 0 is returned silently. The argument may be one of String, Integer, Long, Short.

    - #### toInt

          public static int toInt(java.lang.Object value)

      Converts the argument to an integer. If the conversion fails, a numeric 0 is returned silently. The argument may be one of String, Integer, Long, Short.

    - #### toShort

          public static short toShort(java.lang.String value)

      Converts the string argument to a short value. If the conversion fails, a numeric 0 is returned silently.

    - #### toInt

          public static int toInt(java.lang.String value)

      Converts the string argument to an int value. If the conversion fails, a numeric 0 is returned silently.

    - #### toLong

          public static long toLong(java.lang.String value)

      Converts the string argument to a long. If the conversion fails, a numeric 0 is returned silently.

    - #### toFloat

          public static float toFloat(java.lang.String value)

      Converts the string argument to a float value. If the conversion fails, a numeric 0 is returned silently.

    - #### toDouble

          public static double toDouble(java.lang.String value)

      Converts the string argument to a double value. If the conversion fails, a numeric 0 is returned silently.

    - #### toSingleLineString

          public static java.lang.String toSingleLineString(java.lang.String s)

      Replaces all '\n' by blanks

    - #### toString

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

      Converts the argument to a String. Depending on the argument type different methodologies apply for the conversion.

    - #### toStringList

          public static java.lang.String toStringList(int[] array,
                                      java.lang.String separator)

      Converts the array content to a string list using the given separator for separating the elements.

    - #### toStringList

          public static java.lang.String toStringList(java.util.Collection coll,
                                      java.lang.String separator)

      Converts the collections content to a list of strings separated by the given separator.

    - #### toStringList

          public static java.lang.String toStringList(java.util.Collection coll,
                                      java.lang.String separator,
                                      int maxElements)

      Converts the collections content to a list of strings separated by the given separator.

    - #### toStringList

          public static java.lang.String toStringList(java.util.Map map,
                                      java.lang.String separator,
                                      int maxElements)

      Converts the Maps content to a list of strings separated by the given separator.

    - #### toStringList

          public static java.lang.String toStringList(java.util.Collection coll)

      Converts the collections content to a valueSeparator separated string list.

    - #### toStringList

          public static java.lang.String toStringList(int[] array)

      Converts the array content to a valueSeparator separated string list.

    - #### toStringList

          public static java.lang.String toStringList(double[] array)

      Converts the array content to a valueSeparator separated string list.

    - #### toStringList

          public static java.lang.String toStringList(double[] array,
                                      java.lang.String separator)

      Converts the array content to a string list using the given separator for separating the elements.

    - #### toStringList

          public static java.lang.String toStringList(java.lang.Object[] array)

      Converts the array content to a valueSeparator separated string list.

    - #### toStringArray

          public static java.lang.String[] toStringArray(java.lang.String s)

      Creates a String[] from the given String using ',' as the default delimiter

    - #### toStringArray

          public static java.lang.String[] toStringArray(java.lang.String str,
                                         java.lang.String delim)

      Creates a String[] from the given String using the given delimiter

    - #### toStringArray

          public static java.lang.String[] toStringArray(java.lang.Object[] args)

      Creates a String[] from an object array

    - #### toStringList

          public static java.lang.String toStringList(java.lang.Object[] array,
                                      java.lang.String separator)

      Converts the array content to a string list using the given separator for separating the elements.

    - #### toStringList

          public static java.lang.String toStringList(java.lang.Object[] array,
                                      java.lang.String separator,
                                      int maxElements)

      Converts the array content to a string list using the given separator for separating the elements.

    - #### toSqlValueList

          public static java.lang.String toSqlValueList(java.util.List list)

    - #### toSqlValueList

          public static java.lang.String toSqlValueList(java.lang.Object[] array)

    - #### toCollection

          public static java.util.Collection toCollection(javax.swing.ListModel lm)

      Returns the content of the `ListModel` as a `Collection`.

    - #### toArrayOfType

          public static <E> E[] toArrayOfType(java.lang.Class dataType,
                              java.lang.Object[] items)

      Creates a never null array of the specified dataType and copies the items into it. Note that all objects must be castable to the given dataType.

    - #### toList

          public static <E> java.util.List<E> toList(E... values)

      Wraps the value object into a List

    - #### toTimestamp

          public static DBTimestamp toTimestamp(java.lang.String timestampStr)

      Creates a `DBTimestamp` object from the given string. The string must be formatted according to the `DBTimestamp.toString()` format.
      Returns:
        the DBTimestamp object or null if it could not be parsed.

    - #### toDate

          public static DBDate toDate(java.lang.String dateStr)

      Creates a `DBDate` object from the given string. The string must be formatted according to `Date.toString()` format.
      Returns:
        the DBDate object or null if it could not be parsed.

    - #### toTime

          public static DBTime toTime(java.lang.String timeStr)

      Creates a `DBTime` object from the given string. The string must be formatted according to `DBTime.toString()` format.
      Returns:
        the DBTime object or null if it could not be parsed.

    - #### toAsciiBytes

          public static byte[] toAsciiBytes(long value)

      Converts the long value into a byte array with ASCII digit characters. A negative value gets a '-' sign prefix.

Copyright © 2013 EsprIT-Systems. All Rights Reserved.