Class PropertyConverter
- java.lang.Object
-
- org.apache.commons.configuration2.convert.PropertyConverter
-
public final class PropertyConverter extends java.lang.ObjectA utility class to convert the configuration properties into any type.- Since:
- 2.8.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Objectto(java.lang.Class<?> cls, java.lang.Object value, DefaultConversionHandler convHandler)Converts the specified value object to the given target data class.static java.math.BigDecimaltoBigDecimal(java.lang.Object value)Converts the specified object into a BigDecimal.static java.math.BigIntegertoBigInteger(java.lang.Object value)Converts the specified object into a BigInteger.static java.lang.BooleantoBoolean(java.lang.Object value)Converts the specified object into a Boolean.static java.lang.BytetoByte(java.lang.Object value)Converts the specified object into a Byte.static java.util.CalendartoCalendar(java.lang.Object value, java.lang.String format)Converts the specified object into a Calendar.static java.lang.CharactertoCharacter(java.lang.Object value)Converts the specified value object to aCharacter.static java.awt.ColortoColor(java.lang.Object value)Converts the specified object into a Color.static java.util.DatetoDate(java.lang.Object value, java.lang.String format)Converts the specified object into a Date.static java.lang.DoubletoDouble(java.lang.Object value)Converts the specified object into a Double.static java.time.DurationtoDuration(java.lang.Object value)Converts the specified object into a Duration.static java.io.FiletoFile(java.lang.Object value)Converts the specified object into a File.static java.lang.FloattoFloat(java.lang.Object value)Converts the specified object into a Float.static java.lang.IntegertoInteger(java.lang.Object value)Converts the specified object into an Integer.static java.util.LocaletoLocale(java.lang.Object value)Converts the specified object into a Locale.static java.lang.LongtoLong(java.lang.Object value)Converts the specified object into a Long.static java.nio.file.PathtoPath(java.lang.Object value)Converts the specified object into a Path.static java.util.regex.PatterntoPattern(java.lang.Object value)Converts the specified object into a Pattern.static java.lang.ShorttoShort(java.lang.Object value)Converts the specified object into a Short.static java.net.URItoURI(java.lang.Object value)Converts the specified object into an URI.static java.net.URLtoURL(java.lang.Object value)Converts the specified object into an URL.
-
-
-
Method Detail
-
to
public static java.lang.Object to(java.lang.Class<?> cls, java.lang.Object value, DefaultConversionHandler convHandler) throws ConversionExceptionConverts 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
-
toBoolean
public static java.lang.Boolean toBoolean(java.lang.Object value) throws ConversionExceptionConverts 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, e.g.yesandon. 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
-
toCharacter
public static java.lang.Character toCharacter(java.lang.Object value) throws ConversionExceptionConverts 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
-
toByte
public static java.lang.Byte toByte(java.lang.Object value) throws ConversionExceptionConverts 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
-
toShort
public static java.lang.Short toShort(java.lang.Object value) throws ConversionExceptionConverts 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
-
toInteger
public static java.lang.Integer toInteger(java.lang.Object value) throws ConversionExceptionConverts 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
-
toLong
public static java.lang.Long toLong(java.lang.Object value) throws ConversionExceptionConverts 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
-
toFloat
public static java.lang.Float toFloat(java.lang.Object value) throws ConversionExceptionConverts 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
-
toDouble
public static java.lang.Double toDouble(java.lang.Object value) throws ConversionExceptionConverts 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 java.time.Duration toDuration(java.lang.Object value) throws ConversionExceptionConverts 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
-
toBigInteger
public static java.math.BigInteger toBigInteger(java.lang.Object value) throws ConversionExceptionConverts 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
-
toBigDecimal
public static java.math.BigDecimal toBigDecimal(java.lang.Object value) throws ConversionExceptionConverts 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
-
toFile
public static java.io.File toFile(java.lang.Object value) throws ConversionExceptionConverts 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
-
toPath
public static java.nio.file.Path toPath(java.lang.Object value) throws ConversionExceptionConverts 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
-
toURI
public static java.net.URI toURI(java.lang.Object value) throws ConversionExceptionConverts 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 java.net.URL toURL(java.lang.Object value) throws ConversionExceptionConverts 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
-
toPattern
public static java.util.regex.Pattern toPattern(java.lang.Object value) throws ConversionExceptionConverts 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
-
toLocale
public static java.util.Locale toLocale(java.lang.Object value) throws ConversionExceptionConverts 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
-
toColor
public static java.awt.Color toColor(java.lang.Object value) throws ConversionExceptionConverts 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 java.util.Date toDate(java.lang.Object value, java.lang.String format) throws ConversionExceptionConverts 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
-
toCalendar
public static java.util.Calendar toCalendar(java.lang.Object value, java.lang.String format) throws ConversionExceptionConverts 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
-
-