Class PropertyConverter
java.lang.Object
org.apache.commons.configuration2.convert.PropertyConverter
A utility class to convert the configuration properties into any type.
- Since:
- 2.8.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Objectto(Class<?> cls, Object value, DefaultConversionHandler convHandler) Converts the specified value object to the given target data class.static BigDecimaltoBigDecimal(Object value) Converts the specified object into a BigDecimal.static BigIntegertoBigInteger(Object value) Converts the specified object into a BigInteger.static BooleanConverts the specified object into a Boolean.static ByteConverts the specified object into a Byte.static CalendartoCalendar(Object value, String format) Converts the specified object into a Calendar.static CharactertoCharacter(Object value) Converts the specified value object to aCharacter.static ColorConverts the specified object into a Color.static DateConverts the specified object into a Date.static DoubleConverts the specified object into a Double.static DurationtoDuration(Object value) Converts the specified object into a Duration.static FileConverts the specified object into a File.static FloatConverts the specified object into a Float.static IntegerConverts the specified object into an Integer.static LocaleConverts the specified object into a Locale.static LongConverts the specified object into a Long.static PathConverts the specified object into a Path.static PatternConverts the specified object into a Pattern.static ShortConverts the specified object into a Short.static URIConverts the specified object into an URI.static URLConverts the specified object into an URL.
-
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 inDefaultConversionHandlerobject. 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 valuevalue- the value to convertconvHandler- the conversion handler object- Returns:
- the converted value
- Throws:
ConversionException- if the value is not compatible with the requested type
-
toBigDecimal
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
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
Converts the specified object into a Boolean. Internally theorg.apache.commons.lang.BooleanUtilsclass from the Commons Lang project is used to perform this conversion. This class accepts some more tokens for the boolean value of true, for exampleyesandon. 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
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
Converts the specified object into a Calendar.- Parameters:
value- the value to convertformat- the DateFormat pattern to parse String values- Returns:
- the converted value
- Throws:
ConversionException- thrown if the value cannot be converted to a Calendar
-
toCharacter
Converts the specified value object to aCharacter. 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
Characterobject - Throws:
ConversionException- if the conversion is not possible
-
toColor
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
Converts the specified object into a Date.- Parameters:
value- the value to convertformat- the DateFormat pattern to parse String values- Returns:
- the converted value
- Throws:
ConversionException- thrown if the value cannot be converted to a Calendar
-
toDouble
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
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
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
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
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
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
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
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
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
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
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
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
-