Package org.apache.commons.configuration2.convert

# Class PropertyConverter

java.lang.Object
org.apache.commons.configuration2.convert.PropertyConverter

public final class PropertyConverter extends Object
A utility class to convert the configuration properties into any type.

Since:
  2.8.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Object`
  `to(Class<?> cls, Object value, DefaultConversionHandler convHandler)`
  Converts the specified value object to the given target data class.
  `static BigDecimal`
  `toBigDecimal(Object value)`
  Converts the specified object into a BigDecimal.
  `static BigInteger`
  `toBigInteger(Object value)`
  Converts the specified object into a BigInteger.
  `static Boolean`
  `toBoolean(Object value)`
  Converts the specified object into a Boolean.
  `static Byte`
  `toByte(Object value)`
  Converts the specified object into a Byte.
  `static Calendar`
  `toCalendar(Object value, String format)`
  Converts the specified object into a Calendar.
  `static Character`
  `toCharacter(Object value)`
  Converts the specified value object to a `Character`.
  `static Color`
  `toColor(Object value)`
  Converts the specified object into a Color.
  `static Date`
  `toDate(Object value, String format)`
  Converts the specified object into a Date.
  `static Double`
  `toDouble(Object value)`
  Converts the specified object into a Double.
  `static Duration`
  `toDuration(Object value)`
  Converts the specified object into a Duration.
  `static File`
  `toFile(Object value)`
  Converts the specified object into a File.
  `static Float`
  `toFloat(Object value)`
  Converts the specified object into a Float.
  `static Integer`
  `toInteger(Object value)`
  Converts the specified object into an Integer.
  `static Locale`
  `toLocale(Object value)`
  Converts the specified object into a Locale.
  `static Long`
  `toLong(Object value)`
  Converts the specified object into a Long.
  `static Path`
  `toPath(Object value)`
  Converts the specified object into a Path.
  `static Pattern`
  `toPattern(Object value)`
  Converts the specified object into a Pattern.
  `static Short`
  `toShort(Object value)`
  Converts the specified object into a Short.
  `static URI`
  `toURI(Object value)`
  Converts the specified object into an URI.
  `static URL`
  `toURL(Object value)`
  Converts the specified object into an URL.

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

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

- ## Method Details

  - ### to

    public static Object to(Class<?> cls, Object value, DefaultConversionHandler convHandler) throws ConversionException
    Converts the specified value object to the given target data class. If additional information is required for this conversion, it is obtained from the passed in `DefaultConversionHandler` object. If the class is a primitive type (Integer.TYPE, Boolean.TYPE, etc), the value returned will use the wrapper type (Integer.class, Boolean.class, etc).
    Parameters:
      `cls` - the target class of the converted value
      `value` - the value to convert
      `convHandler` - the conversion handler object
    Returns:
      the converted value
    Throws:
      `ConversionException` - if the value is not compatible with the requested type

  - ### toBigDecimal

    public static BigDecimal toBigDecimal(Object value) throws ConversionException
    Converts the specified object into a BigDecimal.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a BigDecimal

  - ### toBigInteger

    public static BigInteger toBigInteger(Object value) throws ConversionException
    Converts the specified object into a BigInteger.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a BigInteger

  - ### toBoolean

    public static Boolean toBoolean(Object value) throws ConversionException
    Converts the specified object into a Boolean. Internally the `org.apache.commons.lang.BooleanUtils` class from the Commons Lang project is used to perform this conversion. This class accepts some more tokens for the boolean value of true, e.g. `yes` and `on`. Please refer to the documentation of this class for more details.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a boolean

  - ### toByte

    public static Byte toByte(Object value) throws ConversionException
    Converts the specified object into a Byte.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a byte

  - ### toCalendar

    public static Calendar toCalendar(Object value, String format) throws ConversionException
    Converts the specified object into a Calendar.
    Parameters:
      `value` - the value to convert
      `format` - the DateFormat pattern to parse String values
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a Calendar

  - ### toCharacter

    public static Character toCharacter(Object value) throws ConversionException
    Converts the specified value object to a `Character`. This method converts the passed in object to a string. If the string has exactly one character, this character is returned as result. Otherwise, conversion fails.
    Parameters:
      `value` - the value to be converted
    Returns:
      the resulting `Character` object
    Throws:
      `ConversionException` - if the conversion is not possible

  - ### toColor

    public static Color toColor(Object value) throws ConversionException
    Converts the specified object into a Color. If the value is a String, the format allowed is (#)?[0-9A-F]{6}([0-9A-F]{2})?. Examples:
    - FF0000 (red)
    - 0000FFA0 (semi transparent blue)
    - #CCCCCC (gray)
    - #00FF00A0 (semi transparent green)
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a Color

  - ### toDate

    public static Date toDate(Object value, String format) throws ConversionException
    Converts the specified object into a Date.
    Parameters:
      `value` - the value to convert
      `format` - the DateFormat pattern to parse String values
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a Calendar

  - ### toDouble

    public static Double toDouble(Object value) throws ConversionException
    Converts the specified object into a Double.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a Double

  - ### toDuration

    public static Duration toDuration(Object value) throws ConversionException
    Converts the specified object into a Duration.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a Duration
    Since:
      2.8.0

  - ### toFile

    public static File toFile(Object value) throws ConversionException
    Converts the specified object into a File.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a File
    Since:
      2.3

  - ### toFloat

    public static Float toFloat(Object value) throws ConversionException
    Converts the specified object into a Float.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a Float

  - ### toInteger

    public static Integer toInteger(Object value) throws ConversionException
    Converts the specified object into an Integer.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to an integer

  - ### toLocale

    public static Locale toLocale(Object value) throws ConversionException
    Converts the specified object into a Locale.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a Locale

  - ### toLong

    public static Long toLong(Object value) throws ConversionException
    Converts the specified object into a Long.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a Long

  - ### toPath

    public static Path toPath(Object value) throws ConversionException
    Converts the specified object into a Path.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a Path
    Since:
      2.3

  - ### toPattern

    public static Pattern toPattern(Object value) throws ConversionException
    Converts the specified object into a Pattern.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a Pattern

  - ### toShort

    public static Short toShort(Object value) throws ConversionException
    Converts the specified object into a Short.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to a short

  - ### toURI

    public static URI toURI(Object value) throws ConversionException
    Converts the specified object into an URI.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to an URI

  - ### toURL

    public static URL toURL(Object value) throws ConversionException
    Converts the specified object into an URL.
    Parameters:
      `value` - the value to convert
    Returns:
      the converted value
    Throws:
      `ConversionException` - thrown if the value cannot be converted to an URL