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
ConstructorsConstructorDescriptionConstruct a java.time.Duration Converter that throws aConversionExceptionif an error occurs.DurationConverter(boolean useTextFormat) Construct a java.time.DurationL Converter that throws aConversionExceptionif 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 TypeMethodDescriptionprotected <T> TconvertToType(Class<T> type, Object value) Convert a String to a java.time.Duration.protected Class<?> Return the default type thisConverterhandles.Methods inherited from class org.apache.commons.beanutils.converters.AbstractConverter
conversionException, convert, convertArray, convertToString, getDefault, handleError, handleMissing, isUseDefault, setDefaultValue, toString
-
Constructor Details
-
DurationConverter
public DurationConverter()Construct a java.time.Duration Converter that throws aConversionExceptionif an error occurs. -
DurationConverter
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
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 aConversionExceptionif an error occurs.- Parameters:
useTextFormat- if values are in ISO8901 formats.
-
-
Method Details
-
getDefaultType
Return the default type thisConverterhandles.- Specified by:
getDefaultTypein classorg.apache.commons.beanutils.converters.AbstractConverter- Returns:
- The default type this
Converterhandles. - Since:
- 1.8.0
-
convertToType
Convert a String to a java.time.Duration.
- Specified by:
convertToTypein classorg.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
-