Class PropertiesUtil
java.lang.Object
org.apache.jackrabbit.oak.commons.PropertiesUtil
The
PropertiesUtil is a utility class providing some
useful utility methods for converting property types.-
Method Summary
Modifier and TypeMethodDescriptionstatic voidPopulates the bean properties from config instance.static booleanReturns the boolean value of the parameter or thedefaultValueif the parameter isnull.static doubleReturns the parameter as a double or thedefaultValueif the parameter isnullor if the parameter is not aDoubleand cannot be converted to aDoublefrom the parameter's string value.static intReturns the parameter as an integer or thedefaultValueif the parameter isnullor if the parameter is not anIntegerand cannot be converted to anIntegerfrom the parameter's string value.static longReturns the parameter as a long or thedefaultValueif the parameter isnullor if the parameter is not aLongand cannot be converted to aLongfrom the parameter's string value.static ObjectReturns the parameter as a single value.static StringReturns the parameter as a string or thedefaultValueif the parameter isnull.static String[]toStringArray(Object propValue) Returns the parameter as an array of Strings.static String[]toStringArray(Object propValue, String[] defaultArray) Returns the parameter as an array of Strings.
-
Method Details
-
toBoolean
Returns the boolean value of the parameter or thedefaultValueif the parameter isnull. If the parameter is not aBooleanit is converted by callingBoolean.valueOfon the string value of the object.- Parameters:
propValue- the property value ornulldefaultValue- the default boolean value
-
toString
Returns the parameter as a string or thedefaultValueif the parameter isnull.- Parameters:
propValue- the property value ornulldefaultValue- the default string value
-
toLong
Returns the parameter as a long or thedefaultValueif the parameter isnullor if the parameter is not aLongand cannot be converted to aLongfrom the parameter's string value.- Parameters:
propValue- the property value ornulldefaultValue- the default long value
-
toInteger
Returns the parameter as an integer or thedefaultValueif the parameter isnullor if the parameter is not anIntegerand cannot be converted to anIntegerfrom the parameter's string value.- Parameters:
propValue- the property value ornulldefaultValue- the default integer value
-
toDouble
Returns the parameter as a double or thedefaultValueif the parameter isnullor if the parameter is not aDoubleand cannot be converted to aDoublefrom the parameter's string value.- Parameters:
propValue- the property value ornulldefaultValue- the default double value
-
toObject
Returns the parameter as a single value. If the parameter is neither an array nor ajava.util.Collectionthe parameter is returned unmodified. If the parameter is a non-empty array, the first array element is returned. If the property is a non-emptyjava.util.Collection, the first collection element is returned. Otherwisenullis returned.- Parameters:
propValue- the parameter to convert.
-
toStringArray
Returns the parameter as an array of Strings. If the parameter is a scalar value its string value is returned as a single element array. If the parameter is an array, the elements are converted to String objects and returned as an array. If the parameter is a collection, the collection elements are converted to String objects and returned as an array. Otherwise (if the parameter isnull)nullis returned.- Parameters:
propValue- The object to convert.
-
toStringArray
Returns the parameter as an array of Strings. If the parameter is a scalar value its string value is returned as a single element array. If the parameter is an array, the elements are converted to String objects and returned as an array. If the parameter is a collection, the collection elements are converted to String objects and returned as an array. Otherwise (if the property isnull) a provided default value is returned.- Parameters:
propValue- The object to convert.defaultArray- The default array to return.
-
populate
Populates the bean properties from config instance. It supports coercing values for simple types like Number, Integer, Long, Boolean etc. Complex objects are not supported- Parameters:
instance- bean to populateconfig- properties to set in the passed beanvalidate- Flag to validate the configured bean property names against the configured bean class
-