Class TypedProperties
- All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>
Type-aware properties. Extends the JDK
Properties class to provide accessors that convert values to certain
types, using default values if a conversion is not possible.- Since:
- 4.0
- Author:
- Manik Surtani
- See Also:
-
Nested Class Summary
-
Field Summary
Fields inherited from class Properties
defaults -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor that returns an empty instanceTypedProperties(Map<?, ?> p) Copy constructor -
Method Summary
Modifier and TypeMethodDescriptionbooleangetBooleanProperty(String key, boolean defaultValue) Retrieves a boolean property value.booleangetBooleanProperty(String key, boolean defaultValue, boolean doStringReplace) Retrieves a boolean property value.longgetDurationProperty(String key, long defaultValue) Retrieves a duration property value in long.longgetDurationProperty(String key, long defaultValue, boolean doStringReplace) Retrieves a duration property value in long.<T extends Enum<T>>
TgetEnumProperty(String key, Class<T> enumClass, T defaultValue) Retrieves an enum property value.<T extends Enum<T>>
TgetEnumProperty(String key, Class<T> enumClass, T defaultValue, boolean doStringReplace) Retrieves an enum property value.intgetIntProperty(String key, int defaultValue) Retrieves an integer property value.intgetIntProperty(String key, int defaultValue, boolean doStringReplace) Retrieves an integer property value.longgetLongProperty(String key, long defaultValue) Retrieves a long property value.longgetLongProperty(String key, long defaultValue, boolean doStringReplace) Retrieves a long property value.getProperty(String key, boolean doStringReplace) Get the property associated with the key, optionally applying string property replacement as defined inStringPropertyReplacer.replaceProperties(String)to the result.getProperty(String key, String defaultValue, boolean doStringReplace) Get the property associated with the key, optionally applying string property replacement as defined inStringPropertyReplacer.replaceProperties(String)to the result.putIfAbsent(String key, String value) Put a value if the associated key is not presentsetProperty(String key, boolean value) Sets a boolean property value.setProperty(String key, int value) Sets an integer property value.setProperty(String key, long value) Sets a long property value.setProperty(String key, String value) static TypedPropertiestoTypedProperties(Map<?, ?> p) Factory method that converts a JDKMap(includingPropertiesinstance to an instance of TypedProperties, if needed.Methods inherited from class Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, getProperty, hashCode, isEmpty, keys, keySet, list, list, load, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
Constructor Details
-
TypedProperties
Copy constructor- Parameters:
p- properties instance to from. If null, then it is treated as an empty Properties instance.
-
TypedProperties
public TypedProperties()Default constructor that returns an empty instance
-
-
Method Details
-
toTypedProperties
Factory method that converts a JDKMap(includingPropertiesinstance to an instance of TypedProperties, if needed.- Parameters:
p- properties to convert.- Returns:
- A TypedProperties object. Returns an empty TypedProperties instance if p is null.
-
getIntProperty
Retrieves an integer property value. Returns the default if not found or invalid.- Parameters:
key- the property key.defaultValue- the value to return if the key is missing or invalid.- Returns:
- the integer value of the property or the default value.
-
getIntProperty
Retrieves an integer property value. Returns the default if not found or invalid.- Parameters:
key- the property key.defaultValue- the value to return if the key is missing or invalid.doStringReplace- whether to apply string property replacement.- Returns:
- the integer value of the property or the default value.
-
getLongProperty
Retrieves a long property value. Returns the default if not found or invalid.- Parameters:
key- the property key.defaultValue- the value to return if the key is missing or invalid.- Returns:
- the long value of the property or the default value.
-
getLongProperty
Retrieves a long property value. Returns the default if not found or invalid.- Parameters:
key- the property key.defaultValue- the value to return if the key is missing or invalid.doStringReplace- whether to apply string property replacement.- Returns:
- the long value of the property or the default value.
-
getDurationProperty
Retrieves a duration property value in long. Returns the default if not found or invalid.- Parameters:
key- the property key.defaultValue- the value to return if the key is missing or invalid.- Returns:
- the long value of the duration property or the default value.
-
getDurationProperty
Retrieves a duration property value in long. Returns the default if not found or invalid.- Parameters:
key- the property key.defaultValue- the value to return if the key is missing or invalid.doStringReplace- whether to apply string property replacement.- Returns:
- the long value of the duration property or the default value.
-
getBooleanProperty
Retrieves a boolean property value. Returns the default if not found or invalid.- Parameters:
key- the property key.defaultValue- the value to return if the key is missing or invalid.- Returns:
- the boolean value of the property or the default value.
-
getBooleanProperty
Retrieves a boolean property value. Returns the default if not found or invalid.- Parameters:
key- the property key.defaultValue- the value to return if the key is missing or invalid.doStringReplace- whether to apply string property replacement.- Returns:
- the boolean value of the property or the default value.
-
getEnumProperty
Retrieves an enum property value. Returns the default if not found or invalid.- Parameters:
key- the property key.defaultValue- the value to return if the key is missing or invalid.- Returns:
- the enum value of the property or the default value.
-
getEnumProperty
public <T extends Enum<T>> T getEnumProperty(String key, Class<T> enumClass, T defaultValue, boolean doStringReplace) Retrieves an enum property value. Returns the default if not found or invalid.- Parameters:
key- the property key.defaultValue- the value to return if the key is missing or invalid.doStringReplace- whether to apply string property replacement.- Returns:
- the enum value of the property or the default value.
-
getProperty
Get the property associated with the key, optionally applying string property replacement as defined inStringPropertyReplacer.replaceProperties(String)to the result.- Parameters:
key- the hashtable key.defaultValue- a default value.doStringReplace- boolean indicating whether to apply string property replacement- Returns:
- the value in this property list with the specified key value after optionally being inspected for String property replacement
-
getProperty
Get the property associated with the key, optionally applying string property replacement as defined inStringPropertyReplacer.replaceProperties(String)to the result.- Parameters:
key- the hashtable key.doStringReplace- boolean indicating whether to apply string property replacement- Returns:
- the value in this property list with the specified key value after optionally being inspected for String property replacement
-
putIfAbsent
Put a value if the associated key is not present- Parameters:
key- new keyvalue- new value- Returns:
- this TypedProperties instance for method chaining
-
setProperty
- Overrides:
setPropertyin classProperties
-
setProperty
Sets an integer property value.- Parameters:
key- the property key.value- the integer value to set.- Returns:
- this
TypedPropertiesinstance for chaining.
-
setProperty
Sets a long property value.- Parameters:
key- the property key.value- the long value to set.- Returns:
- this
TypedPropertiesinstance for chaining.
-
setProperty
Sets a boolean property value.- Parameters:
key- the property key.value- the boolean value to set.- Returns:
- this
TypedPropertiesinstance for chaining.
-