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 booleangetBoolean(String key, boolean def) Gets the system property value associated with the given key and attempts to parse it a boolean.static booleangetBoolean(Properties props, String key, boolean def) Gets the string associated with the given key in thePropertiesobject and attempts to parse it a boolean.static doubleGets the system property value associated with the given key and attempts to parse it as a double-precision floating point number.static doublegetDouble(Properties props, String key, double def) Gets the string associated with the given key in thePropertiesobject and attempts to parse it as a double-precision floating point number.static floatGets the system property value associated with the given key and attempts to parse it as a floating point number.static floatgetFloat(Properties props, String key, float def) Gets the string associated with the given key in thePropertiesobject and attempts to parse it as a floating point number.static intGets the system property value associated with the given key and attempts to parse it as an integer.static intgetInt(Properties props, String key, int def) Gets the string associated with the given key in thePropertiesobject and attempts to parse it as an integer.static longGets the system property value associated with the given key and attempts to parse it as a long integer.static longgetLong(Properties props, String key, long def) Gets the string associated with the given key in thePropertiesobject and attempts to parse it as a long integer.static StringReturns the system property value associated with the given key.static StringgetString(Properties props, String key, String def) Returns the string associated with the given key in thePropertiesobject.static booleanisPropertySet(String key) Returns whether the system property identified by the given key is set.static booleansetDefault(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:
trueif 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:
trueif a system property with the given key existed already- Since:
- 2.11.0
-
getString
Returns the string associated with the given key in thePropertiesobject. 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 thePropertiesobject 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 thePropertiesobject 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 thePropertiesobject 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 thePropertiesobject 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 thePropertiesobject 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
trueif the string equals"true"or"1"and asfalseif 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:
-