org.apache.jorphan.util

## Class Converter

- java.lang.Object
- - org.apache.jorphan.util.Converter

-     public class Converter
      extends java.lang.Object

  Converter utilities for TestBeans

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Converter()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.Object` | `convert(java.lang.Object value, java.lang.Class<?> toType)` Convert the given value object to an object of the given type
    `static java.lang.String` | `formatCalendar(java.util.Calendar date, java.lang.String pattern)` Format a calendar using a given pattern
    `static java.lang.String` | `formatDate(java.util.Calendar date, java.lang.String pattern)` Format a date using a given pattern
    `static java.lang.String` | `formatDate(java.util.Date date, java.lang.String pattern)` Format a date using a given pattern
    `static java.lang.String` | `formatDate(java.sql.Date date, java.lang.String pattern)` Format a date using a given pattern
    `static java.lang.String` | `formatDate(java.lang.String date, java.lang.String pattern)` Format a date using a given pattern
    `static boolean` | `getBoolean(java.lang.Object o)` Convert object to boolean, or `false` if conversion failed
    `static boolean` | `getBoolean(java.lang.Object o, boolean defaultValue)` Convert object to boolean, or `defaultValue` if conversion failed
    `static java.util.Calendar` | `getCalendar(java.lang.Object o)` Converts the given object to a calendar object.
    `static java.util.Calendar` | `getCalendar(java.lang.Object date, java.util.Calendar defaultValue)` Converts the given object to a calendar object.
    `static char` | `getChar(java.lang.Object o)` Convert object to char, or ' ' if no conversion can be applied
    `static char` | `getChar(java.lang.Object o, char defaultValue)` Convert object to char, or `defaultValue` if no conversion can be applied
    `static java.util.Date` | `getDate(java.lang.Object date)` Converts the given object to a `Date` object.
    `static java.util.Date` | `getDate(java.lang.Object date, java.util.Date defaultValue)` Converts the given object to a `Date` object.
    `static double` | `getDouble(java.lang.Object o)` Convert object to double, or `0` if conversion failed
    `static double` | `getDouble(java.lang.Object o, double defaultValue)` Convert object to double, or `defaultValue` if conversion failed
    `static java.io.File` | `getFile(java.lang.Object o)` Converts an object to a `File`
    `static float` | `getFloat(java.lang.Object o)` Convert object to float, or `0` if conversion failed
    `static float` | `getFloat(java.lang.Object o, float defaultValue)` Convert object to float, or `defaultValue` if conversion failed
    `static int` | `getInt(java.lang.Object o)` Converts object to an integer, defaults to `0` if object is not convertible or is `null`.
    `static int` | `getInt(java.lang.Object o, int defaultValue)` Convert object to integer, return `defaultValue` if object is not convertible or is `null`.
    `static long` | `getLong(java.lang.Object o)` Converts object to a long, defaults to `0` if object is not convertible or is `null`
    `static long` | `getLong(java.lang.Object o, long defaultValue)` Converts object to a long, return `defaultValue` if object is not convertible or is `null`.
    `static java.lang.String` | `getString(java.lang.Object o)` Converts object to a String, defaults to empty string if object is null.
    `static java.lang.String` | `getString(java.lang.Object o, java.lang.String defaultValue)` Converts object to a String, return `defaultValue` if object is `null`.
    `static java.lang.String` | `insertLineBreaks(java.lang.String v, java.lang.String insertion)` Replace newlines "\n" with `insertion`

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

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

- - ### Constructor Detail

    - #### Converter

          public Converter()

  - ### Method Detail

    - #### convert

          public static java.lang.Object convert(java.lang.Object value,
                                                 java.lang.Class<?> toType)

      Convert the given value object to an object of the given type
      Parameters:
        `value` - object to convert
        `toType` - type to convert object to
      Returns:
        converted object or original value if no conversion could be applied

    - #### getCalendar

          public static java.util.Calendar getCalendar(java.lang.Object date,
                                                       java.util.Calendar defaultValue)

      Converts the given object to a calendar object. Defaults to the `defaultValue` if the given object can't be converted.
      Parameters:
        `date` - object that should be converted to a `Calendar`
        `defaultValue` - default value that will be returned if `date` can not be converted
      Returns:
        `Calendar` representing the given `date` or `defaultValue` if conversion failed

    - #### getCalendar

          public static java.util.Calendar getCalendar(java.lang.Object o)

      Converts the given object to a calendar object. Defaults to a calendar using the current time if the given object can't be converted.
      Parameters:
        `o` - object that should be converted to a `Calendar`
      Returns:
        `Calendar` representing the given `o` or a new `GregorianCalendar` using the current time if conversion failed

    - #### getDate

          public static java.util.Date getDate(java.lang.Object date)

      Converts the given object to a `Date` object. Defaults to the current time if the given object can't be converted.
      Parameters:
        `date` - object that should be converted to a `Date`
      Returns:
        `Date` representing the given `date` or the current time if conversion failed

    - #### getDate

          public static java.util.Date getDate(java.lang.Object date,
                                               java.util.Date defaultValue)

      Converts the given object to a `Date` object. Defaults to the `defaultValue` if the given object can't be converted.
      Parameters:
        `date` - object that should be converted to a `Date`
        `defaultValue` - default value that will be returned if `date` can not be converted
      Returns:
        `Date` representing the given `date` or `defaultValue` if conversion failed

    - #### getFloat

          public static float getFloat(java.lang.Object o,
                                       float defaultValue)

      Convert object to float, or `defaultValue` if conversion failed
      Parameters:
        `o` - object to convert
        `defaultValue` - default value to use, when conversion failed
      Returns:
        converted float or `defaultValue` if conversion failed

    - #### getFloat

          public static float getFloat(java.lang.Object o)

      Convert object to float, or `0` if conversion failed
      Parameters:
        `o` - object to convert
      Returns:
        converted float or `0` if conversion failed

    - #### getDouble

          public static double getDouble(java.lang.Object o,
                                         double defaultValue)

      Convert object to double, or `defaultValue` if conversion failed
      Parameters:
        `o` - object to convert
        `defaultValue` - default value to use, when conversion failed
      Returns:
        converted double or `defaultValue` if conversion failed

    - #### getDouble

          public static double getDouble(java.lang.Object o)

      Convert object to double, or `0` if conversion failed
      Parameters:
        `o` - object to convert
      Returns:
        converted double or `0` if conversion failed

    - #### getBoolean

          public static boolean getBoolean(java.lang.Object o)

      Convert object to boolean, or `false` if conversion failed
      Parameters:
        `o` - object to convert
      Returns:
        converted boolean or `false` if conversion failed

    - #### getBoolean

          public static boolean getBoolean(java.lang.Object o,
                                           boolean defaultValue)

      Convert object to boolean, or `defaultValue` if conversion failed
      Parameters:
        `o` - object to convert
        `defaultValue` - default value to use, when conversion failed
      Returns:
        converted boolean or `defaultValue` if conversion failed

    - #### getInt

          public static int getInt(java.lang.Object o,
                                   int defaultValue)

      Convert object to integer, return `defaultValue` if object is not convertible or is `null`.
      Parameters:
        `o` - object to convert
        `defaultValue` - default value to be used when no conversion can be done
      Returns:
        converted int or default value if conversion failed

    - #### getChar

          public static char getChar(java.lang.Object o)

      Convert object to char, or ' ' if no conversion can be applied
      Parameters:
        `o` - object to convert
      Returns:
        converted char or ' ' if conversion failed

    - #### getChar

          public static char getChar(java.lang.Object o,
                                     char defaultValue)

      Convert object to char, or `defaultValue` if no conversion can be applied
      Parameters:
        `o` - object to convert
        `defaultValue` - default value to use, when conversion failed
      Returns:
        converted char or `defaultValue` if conversion failed

    - #### getInt

          public static int getInt(java.lang.Object o)

      Converts object to an integer, defaults to `0` if object is not convertible or is `null`.
      Parameters:
        `o` - object to convert
      Returns:
        converted int, or `0` if conversion failed

    - #### getLong

          public static long getLong(java.lang.Object o,
                                     long defaultValue)

      Converts object to a long, return `defaultValue` if object is not convertible or is `null`.
      Parameters:
        `o` - object to convert
        `defaultValue` - default value to use, when conversion failed
      Returns:
        converted long or `defaultValue` when conversion failed

    - #### getLong

          public static long getLong(java.lang.Object o)

      Converts object to a long, defaults to `0` if object is not convertible or is `null`
      Parameters:
        `o` - object to convert
      Returns:
        converted long or `0` if conversion failed

    - #### formatDate

          public static java.lang.String formatDate(java.util.Date date,
                                                    java.lang.String pattern)

      Format a date using a given pattern
      Parameters:
        `date` - date to format
        `pattern` - pattern to use for formatting
      Returns:
        formatted date, or empty string if date was `null`
      Throws:
        `java.lang.IllegalArgumentException` - when `pattern` is invalid

    - #### formatDate

          public static java.lang.String formatDate(java.sql.Date date,
                                                    java.lang.String pattern)

      Format a date using a given pattern
      Parameters:
        `date` - date to format
        `pattern` - pattern to use for formatting
      Returns:
        formatted date, or empty string if date was `null`
      Throws:
        `java.lang.IllegalArgumentException` - when `pattern` is invalid

    - #### formatDate

          public static java.lang.String formatDate(java.lang.String date,
                                                    java.lang.String pattern)

      Format a date using a given pattern
      Parameters:
        `date` - date to format
        `pattern` - pattern to use for formatting
      Returns:
        formatted date, or empty string if date was `null`
      Throws:
        `java.lang.IllegalArgumentException` - when `pattern` is invalid

    - #### formatDate

          public static java.lang.String formatDate(java.util.Calendar date,
                                                    java.lang.String pattern)

      Format a date using a given pattern
      Parameters:
        `date` - date to format
        `pattern` - pattern to use for formatting
      Returns:
        formatted date, or empty string if date was `null`
      Throws:
        `java.lang.IllegalArgumentException` - when `pattern` is invalid

    - #### formatCalendar

          public static java.lang.String formatCalendar(java.util.Calendar date,
                                                        java.lang.String pattern)

      Format a calendar using a given pattern
      Parameters:
        `date` - calendar to format
        `pattern` - pattern to use for formatting
      Returns:
        formatted date, or empty string if date was `null`
      Throws:
        `java.lang.IllegalArgumentException` - when `pattern` is invalid

    - #### getString

          public static java.lang.String getString(java.lang.Object o,
                                                   java.lang.String defaultValue)

      Converts object to a String, return `defaultValue` if object is `null`.
      Parameters:
        `o` - object to convert
        `defaultValue` - default value to use when conversion failed
      Returns:
        converted String or `defaultValue` when conversion failed

    - #### insertLineBreaks

          public static java.lang.String insertLineBreaks(java.lang.String v,
                                                          java.lang.String insertion)

      Replace newlines "\n" with `insertion`
      Parameters:
        `v` - String in which the newlines should be replaced
        `insertion` - new string which should be used instead of "\n"
      Returns:
        new string with newlines replaced by `insertion`

    - #### getString

          public static java.lang.String getString(java.lang.Object o)

      Converts object to a String, defaults to empty string if object is null.
      Parameters:
        `o` - object to convert
      Returns:
        converted String or empty string when conversion failed

    - #### getFile

          public static java.io.File getFile(java.lang.Object o)

      Converts an object to a `File`
      Parameters:
        `o` - object to convert (must be a `String` or a `File`)
      Returns:
        converted file
      Throws:
        `java.lang.IllegalArgumentException` - when object can not be converted

Copyright © 1998-2018 Apache Software Foundation. All Rights Reserved.