Package org.apache.torque.dsfactory.converters

# Class DurationConverter

java.lang.Object
org.apache.commons.beanutils.converters.AbstractConverter
org.apache.torque.dsfactory.converters.DurationConverter

All Implemented Interfaces:
  `org.apache.commons.beanutils.Converter`

public final class DurationConverter extends org.apache.commons.beanutils.converters.AbstractConverter
`Converter` implementation that handles conversion to and from java.time.Duration objects.

Can be configured to either return a default value or throw a `ConversionException` if a conversion error occurs.

Since:
  1.3
Version:
  $Id$

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DurationConverter()`
  Construct a java.time.Duration Converter that throws a `ConversionException` if an error occurs.
  `DurationConverter(boolean useTextFormat)`
  Construct a java.time.DurationL Converter that throws a `ConversionException` if an error occurs.
  `DurationConverter(Object defaultValue)`
  Construct a java.time.DurationL Converter that returns a default value if an error occurs.
  `DurationConverter(Object defaultValue, boolean useTextFormat)`
  Construct a java.time.DurationL Converter that returns a default value if an error occurs.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected <T> T`
  `convertToType(Class<T> type, Object value)`
  Convert a String to a java.time.Duration.
  `protected Class<?>`
  `getDefaultType()`
  Return the default type this `Converter` handles.

  ### Methods inherited from class org.apache.commons.beanutils.converters.AbstractConverter

  `conversionException, convert, convertArray, convertToString, getDefault, handleError, handleMissing, isUseDefault, setDefaultValue, toString`

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

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

- ## Constructor Details

  - ### DurationConverter

    public DurationConverter()
    Construct a java.time.Duration Converter that throws a `ConversionException` if an error occurs.

  - ### DurationConverter

    public DurationConverter(Object defaultValue, boolean useTextFormat)
    Construct a java.time.DurationL Converter that returns a default value if an error occurs.
    Parameters:
      `defaultValue` - The default value to be returned if the value to be converted is missing or an error occurs converting the value.
      `useTextFormat` - if values are in ISO8901 formats.

  - ### DurationConverter

    public DurationConverter(Object defaultValue)
    Construct a java.time.DurationL Converter that returns a default value if an error occurs.
    Parameters:
      `defaultValue` - The default value to be returned if the value to be converted is missing or an error occurs converting the value.

  - ### DurationConverter

    public DurationConverter(boolean useTextFormat)
    Construct a java.time.DurationL Converter that throws a `ConversionException` if an error occurs.
    Parameters:
      `useTextFormat` - if values are in ISO8901 formats.

- ## Method Details

  - ### getDefaultType

    protected Class<?> getDefaultType()
    Return the default type this `Converter` handles.
    Specified by:
      `getDefaultType` in class `org.apache.commons.beanutils.converters.AbstractConverter`
    Returns:
      The default type this `Converter` handles.
    Since:
      1.8.0

  - ### convertToType

    protected <T> T convertToType(Class<T> type, Object value) throws Throwable

    Convert a String to a java.time.Duration.

    Specified by:
      `convertToType` in class `org.apache.commons.beanutils.converters.AbstractConverter`
    Type Parameters:
      `T` - Target type of the conversion.
    Parameters:
      `type` - Data type to which this value should be converted.
      `value` - The input value to be converted.
    Returns:
      The converted value.
    Throws:
      `Throwable` - if an error occurs converting to the specified type