Package org.infinispan.commons.util
Class TypedProperties
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable<Object,Object>
-
- java.util.Properties
-
- org.infinispan.commons.util.TypedProperties
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<Object,Object>
public class TypedProperties extends Properties
Type-aware properties. Extends the JDKProperties
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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description TypedProperties()
Default constructor that returns an empty instanceTypedProperties(Properties p)
Copy constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
getBooleanProperty(String key, boolean defaultValue)
boolean
getBooleanProperty(String key, boolean defaultValue, boolean doStringReplace)
<T extends Enum<T>>
TgetEnumProperty(String key, Class<T> enumClass, T defaultValue)
<T extends Enum<T>>
TgetEnumProperty(String key, Class<T> enumClass, T defaultValue, boolean doStringReplace)
int
getIntProperty(String key, int defaultValue)
int
getIntProperty(String key, int defaultValue, boolean doStringReplace)
long
getLongProperty(String key, long defaultValue)
long
getLongProperty(String key, long defaultValue, boolean doStringReplace)
String
getProperty(String key, boolean doStringReplace)
Get the property associated with the key, optionally applying string property replacement as defined inStringPropertyReplacer.replaceProperties(java.lang.String)
to the result.String
getProperty(String key, String defaultValue, boolean doStringReplace)
Get the property associated with the key, optionally applying string property replacement as defined inStringPropertyReplacer.replaceProperties(java.lang.String)
to the result.TypedProperties
putIfAbsent(String key, String value)
Put a value if the associated key is not presentTypedProperties
setProperty(String key, boolean value)
TypedProperties
setProperty(String key, int value)
TypedProperties
setProperty(String key, long value)
TypedProperties
setProperty(String key, String value)
static TypedProperties
toTypedProperties(Properties p)
Factory method that converts a JDKProperties
instance to an instance of TypedProperties, if needed.
-
-
-
Constructor Detail
-
TypedProperties
public TypedProperties(Properties p)
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 Detail
-
toTypedProperties
public static TypedProperties toTypedProperties(Properties p)
Factory method that converts a JDKProperties
instance 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
public int getIntProperty(String key, int defaultValue)
-
getIntProperty
public int getIntProperty(String key, int defaultValue, boolean doStringReplace)
-
getLongProperty
public long getLongProperty(String key, long defaultValue)
-
getLongProperty
public long getLongProperty(String key, long defaultValue, boolean doStringReplace)
-
getBooleanProperty
public boolean getBooleanProperty(String key, boolean defaultValue)
-
getBooleanProperty
public boolean getBooleanProperty(String key, boolean defaultValue, boolean doStringReplace)
-
getEnumProperty
public <T extends Enum<T>> T getEnumProperty(String key, Class<T> enumClass, T defaultValue)
-
getEnumProperty
public <T extends Enum<T>> T getEnumProperty(String key, Class<T> enumClass, T defaultValue, boolean doStringReplace)
-
getProperty
public String getProperty(String key, String defaultValue, boolean doStringReplace)
Get the property associated with the key, optionally applying string property replacement as defined inStringPropertyReplacer.replaceProperties(java.lang.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
public String getProperty(String key, boolean doStringReplace)
Get the property associated with the key, optionally applying string property replacement as defined inStringPropertyReplacer.replaceProperties(java.lang.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
public TypedProperties putIfAbsent(String key, String value)
Put a value if the associated key is not present- Parameters:
key
- new keyvalue
- new value- Returns:
- this TypedProperties instance for method chaining
-
setProperty
public TypedProperties setProperty(String key, String value)
-
setProperty
public TypedProperties setProperty(String key, int value)
-
setProperty
public TypedProperties setProperty(String key, long value)
-
setProperty
public TypedProperties setProperty(String key, boolean value)
-
-