Package io.pravega.common.util
Class TypedProperties
- java.lang.Object
-
- io.pravega.common.util.TypedProperties
-
public class TypedProperties extends java.lang.Object* Wrapper for a java.util.Properties object, that sections it based on a namespace. Each property in the wrapped object will be prefixed by a namespace.Example:
- foo.key1=value1
- foo.key2=value2
- bar.key1=value3
- bar.key3=value4
-
-
Constructor Summary
Constructors Constructor Description TypedProperties(java.util.Properties properties, java.lang.String namespace)Creates a new instance of the TypedProperties class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringget(Property<java.lang.String> property)Gets the value of a String property.booleangetBoolean(Property<java.lang.Boolean> property)Gets the value of a boolean property.doublegetDouble(Property<java.lang.Double> property)Gets the value of a Double property.java.time.DurationgetDuration(Property<java.lang.Integer> property, java.time.temporal.TemporalUnit unit)Gets a Duration from an Integer property only if it is greater than 0.<T extends java.lang.Enum<T>>
TgetEnum(Property<T> property, java.lang.Class<T> enumClass)Gets the value of an Enumeration property.intgetInt(Property<java.lang.Integer> property)Gets the value of an Integer property.longgetLong(Property<java.lang.Long> property)Gets the value of a Long property.intgetNonNegativeInt(Property<java.lang.Integer> property)Gets the value of an Integer property only if it is non-negative (greater than or equal to 0).intgetPositiveInt(Property<java.lang.Integer> property)Gets the value of an Integer property only if it is greater than 0.longgetPositiveLong(Property<java.lang.Long> property)Gets the value of an Long property only if it is greater than 0.
-
-
-
Method Detail
-
get
public java.lang.String get(Property<java.lang.String> property) throws ConfigurationException
Gets the value of a String property.- Parameters:
property- The Property to get.- Returns:
- The property value or default value, if no such is defined in the base Properties.
- Throws:
ConfigurationException- When the given property name does not exist within the current component and the property does not have a default value set.
-
getInt
public int getInt(Property<java.lang.Integer> property) throws ConfigurationException
Gets the value of an Integer property.- Parameters:
property- The Property to get.- Returns:
- The property value or default value, if no such is defined in the base Properties.
- Throws:
ConfigurationException- When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as an Integer.
-
getLong
public long getLong(Property<java.lang.Long> property) throws ConfigurationException
Gets the value of a Long property.- Parameters:
property- The Property to get.- Returns:
- The property value or default value, if no such is defined in the base Properties.
- Throws:
ConfigurationException- When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a Long.
-
getDouble
public double getDouble(Property<java.lang.Double> property) throws ConfigurationException
Gets the value of a Double property.- Parameters:
property- The Property to get.- Returns:
- The property value or default value, if no such is defined in the base Properties.
- Throws:
ConfigurationException- When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a Double.
-
getEnum
public <T extends java.lang.Enum<T>> T getEnum(Property<T> property, java.lang.Class<T> enumClass) throws ConfigurationException
Gets the value of an Enumeration property.- Type Parameters:
T- Type of Enumeration.- Parameters:
property- The Property to get.enumClass- Class defining return type.- Returns:
- The property value or default value, if no such is defined in the base Properties.
- Throws:
ConfigurationException- When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as the given Enum.
-
getBoolean
public boolean getBoolean(Property<java.lang.Boolean> property) throws ConfigurationException
Gets the value of a boolean property. Notes:- "true", "yes" and "1" (case insensitive) map to boolean "true".
- "false", "no" and "0" (case insensitive) map to boolean "false".
- Parameters:
property- The Property to get.- Returns:
- The property value or default value, if no such is defined in the base Properties.
- Throws:
ConfigurationException- When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a Boolean.
-
getPositiveInt
public int getPositiveInt(Property<java.lang.Integer> property)
Gets the value of an Integer property only if it is greater than 0.- Parameters:
property- The Property to get.- Returns:
- The property value or default value, if no such is defined in the base Properties.
- Throws:
ConfigurationException- When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a positive Integer.
-
getNonNegativeInt
public int getNonNegativeInt(Property<java.lang.Integer> property)
Gets the value of an Integer property only if it is non-negative (greater than or equal to 0).- Parameters:
property- The Property to get.- Returns:
- The property value or default value, if no such is defined in the base Properties.
- Throws:
ConfigurationException- When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a non-negative Integer.
-
getPositiveLong
public long getPositiveLong(Property<java.lang.Long> property)
Gets the value of an Long property only if it is greater than 0.- Parameters:
property- The Property to get.- Returns:
- The property value or default value, if no such is defined in the base Properties.
- Throws:
ConfigurationException- When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a positive Long.
-
getDuration
public java.time.Duration getDuration(Property<java.lang.Integer> property, java.time.temporal.TemporalUnit unit)
Gets a Duration from an Integer property only if it is greater than 0.- Parameters:
property- The Property to get.unit- Temporal unit related to the value associated to this property (i.e, seconds, millis).- Returns:
- The property value or default value, if no such is defined in the base Properties.
- Throws:
ConfigurationException- When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a positive Integer.
-
-