Package org.omegazero.common.util
Class PropertyUtil
java.lang.Object
org.omegazero.common.util.PropertyUtil
Contains utility methods for reading
Properties
and system properties.- Since:
- 2.2
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
getBoolean
(String key, boolean def) Gets the system property value associated with the given key and attempts to parse it a boolean.static boolean
getBoolean
(Properties props, String key, boolean def) Gets the string associated with the given key in theProperties
object and attempts to parse it a boolean.static double
Gets the system property value associated with the given key and attempts to parse it as a double-precision floating point number.static double
getDouble
(Properties props, String key, double def) Gets the string associated with the given key in theProperties
object and attempts to parse it as a double-precision floating point number.static float
Gets the system property value associated with the given key and attempts to parse it as a floating point number.static float
getFloat
(Properties props, String key, float def) Gets the string associated with the given key in theProperties
object and attempts to parse it as a floating point number.static int
Gets the system property value associated with the given key and attempts to parse it as an integer.static int
getInt
(Properties props, String key, int def) Gets the string associated with the given key in theProperties
object and attempts to parse it as an integer.static long
Gets the system property value associated with the given key and attempts to parse it as a long integer.static long
getLong
(Properties props, String key, long def) Gets the string associated with the given key in theProperties
object and attempts to parse it as a long integer.static String
Returns the system property value associated with the given key.static String
getString
(Properties props, String key, String def) Returns the string associated with the given key in theProperties
object.static boolean
isPropertySet
(String key) Returns whether the system property identified by the given key is set.static boolean
setDefault
(String key, String value) Sets the system property with the given key to the given value, if no property with the given key is already set.
-
Method Details
-
getString
Returns the system property value associated with the given key. If the property does not exist, def is returned.- Parameters:
key
- The keydef
- The default value- Returns:
- The value of key, or def if the property does not exist
- See Also:
-
getInt
Gets the system property value associated with the given key and attempts to parse it as an integer. If the property does not exist or the value is not a valid number, def is returned.- Parameters:
key
- The keydef
- The default value- Returns:
- The numeric value of key, or def if the property is invalid
- See Also:
-
getLong
Gets the system property value associated with the given key and attempts to parse it as a long integer. If the property does not exist or the value is not a valid number, def is returned.- Parameters:
key
- The keydef
- The default value- Returns:
- The numeric value of key, or def if the property is invalid
- See Also:
-
getFloat
Gets the system property value associated with the given key and attempts to parse it as a floating point number. If the property does not exist or the value is not a valid number, def is returned.- Parameters:
key
- The keydef
- The default value- Returns:
- The numeric value of key, or def if the property is invalid
- See Also:
-
getDouble
Gets the system property value associated with the given key and attempts to parse it as a double-precision floating point number. If the property does not exist or the value is not a valid number, def is returned.- Parameters:
key
- The keydef
- The default value- Returns:
- The numeric value of key, or def if the property is invalid
- See Also:
-
getBoolean
Gets the system property value associated with the given key and attempts to parse it a boolean. If the property does not exist or the value is not a valid boolean, def is returned.- Parameters:
key
- The keydef
- The default value- Returns:
- The boolean value of key, or def if the property is invalid
- See Also:
-
isPropertySet
Returns whether the system property identified by the given key is set.- Parameters:
key
- The key- Returns:
true
if a system property with the given key exists- Since:
- 2.8
-
setDefault
Sets the system property with the given key to the given value, if no property with the given key is already set.- Parameters:
key
- The keyvalue
- The value- Returns:
true
if a system property with the given key existed already- Since:
- 2.11.0
-
getString
Returns the string associated with the given key in theProperties
object. If there is no mapping for the given key, the value passed to def is returned.- Parameters:
props
- The propertieskey
- The keydef
- The default value to return if there is no value for the key- Returns:
- The value of key, or def if there is no value associated with the key
- See Also:
-
getInt
Gets the string associated with the given key in theProperties
object and attempts to parse it as an integer. If there is no mapping for the given key or the value is not a valid number, the value passed to def is returned.- Parameters:
props
- The propertieskey
- The keydef
- The default value to return if there is no value for the key or the value is not valid- Returns:
- The numeric value of key, or def if there is no value associated with the key or the value is not a valid number
- See Also:
-
getLong
Gets the string associated with the given key in theProperties
object and attempts to parse it as a long integer. If there is no mapping for the given key or the value is not a valid number, the value passed to def is returned.- Parameters:
props
- The propertieskey
- The keydef
- The default value to return if there is no value for the key or the value is not valid- Returns:
- The numeric value of key, or def if there is no value associated with the key or the value is not a valid number
- See Also:
-
getFloat
Gets the string associated with the given key in theProperties
object and attempts to parse it as a floating point number. If there is no mapping for the given key or the value is not a valid number, the value passed to def is returned.- Parameters:
props
- The propertieskey
- The keydef
- The default value to return if there is no value for the key or the value is not valid- Returns:
- The numeric value of key, or def if there is no value associated with the key or the value is not a valid number
- See Also:
-
getDouble
Gets the string associated with the given key in theProperties
object and attempts to parse it as a double-precision floating point number. If there is no mapping for the given key or the value is not a valid number, the value passed to def is returned.- Parameters:
props
- The propertieskey
- The keydef
- The default value to return if there is no value for the key or the value is not valid- Returns:
- The numeric value of key, or def if there is no value associated with the key or the value is not a valid number
- See Also:
-
getBoolean
Gets the string associated with the given key in theProperties
object and attempts to parse it a boolean. If there is no mapping for the given key or the value is not a valid boolean, the value passed to def is returned.A string will be interpreted as the boolean value
true
if the string equals"true"
or"1"
and asfalse
if the string equals"false"
or"0"
.- Parameters:
props
- The propertieskey
- The keydef
- The default value to return if there is no value for the key or the value is not valid- Returns:
- The boolean value of key, or def if there is no value associated with the key or the value is not a valid boolean
- See Also:
-