public final class PropertiesReader extends Object
| Constructor and Description |
|---|
PropertiesReader(Properties properties) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
getBoolean(String property)
Reads a boolean property.
|
boolean |
getBoolean(String property,
boolean defaultValue)
Reads a boolean property.
|
Class<?> |
getClass(String property)
Reads a class property.
|
Class<?> |
getClass(String property,
Class<?> defaultValue)
Reads a class property.
|
<T> Collection<T> |
getCollection(String prefix,
Function<String,T> factory)
Reads a collection of properties based on a prefix.
|
double |
getDouble(String property)
Reads a double property.
|
double |
getDouble(String property,
double defaultValue)
Reads a double property.
|
Duration |
getDuration(String property)
Reads a duration property.
|
Duration |
getDuration(String property,
Duration defaultValue)
Reads a duration property.
|
<T extends Enum<T>> |
getEnum(String property,
Class<T> type)
Reads an enum property.
|
<T extends Enum<T>> |
getEnum(String property,
Class<T> type,
T defaultValue)
Reads an enum property.
|
File |
getFile(String property)
Reads a file property.
|
File |
getFile(String property,
File defaultValue)
Reads a file property.
|
float |
getFloat(String property)
Reads a float property.
|
float |
getFloat(String property,
float defaultValue)
Reads a float property.
|
int |
getInteger(String property)
Reads an integer property.
|
int |
getInteger(String property,
int defaultValue)
Reads an integer property.
|
long |
getLong(String property)
Reads a long property.
|
long |
getLong(String property,
long defaultValue)
Reads a long property.
|
<K,V> Map<K,V> |
getMap(String prefix,
Function<String,K> keyFactory,
Function<String,V> valueFactory)
Returns a map of properties for a given prefix.
|
short |
getShort(String property)
Reads a short property.
|
short |
getShort(String property,
short defaultValue)
Reads a short property.
|
String |
getString(String property)
Reads a string property, returning a default value if the property is not present.
|
String |
getString(String property,
String defaultValue)
Reads a string property, returning a default value if the property is not present.
|
static PropertiesReader |
load(String propertiesFile)
Loads a properties reader for the given properties file on the local filesystem.
|
static PropertiesReader |
loadFromClasspath(String propertiesFile)
Loads a properties reader for the given properties file on the classpath.
|
Properties |
properties()
Returns the underlying properties.
|
public PropertiesReader(Properties properties)
public static PropertiesReader load(String propertiesFile)
propertiesFile - The properties file for which to load the reader.public static PropertiesReader loadFromClasspath(String propertiesFile)
propertiesFile - The properties file for which to load the reader.public Properties properties()
public <T> Collection<T> getCollection(String prefix, Function<String,T> factory)
T - The collection value type.prefix - The prefix for which to read properties.factory - The factory to call for each property name in the collection.public <K,V> Map<K,V> getMap(String prefix, Function<String,K> keyFactory, Function<String,V> valueFactory)
K - The map key type.V - The map value type.prefix - The prefix for which to return a map of property values.keyFactory - A converter function to convert the map keys.valueFactory - A converter function to convert the map values.public Class<?> getClass(String property)
property - The property name.ConfigurationException - if the property is not presentpublic Class<?> getClass(String property, Class<?> defaultValue)
property - The property name.defaultValue - The default value to return if the property is not presentpublic File getFile(String property)
property - The property name.ConfigurationException - if the property is not presentpublic File getFile(String property, File defaultValue)
property - The property name.defaultValue - The default value to return if the property is not presentpublic <T extends Enum<T>> T getEnum(String property, Class<T> type)
T - The enum type.property - The property name.type - The enum type.ConfigurationException - if the property is not presentpublic <T extends Enum<T>> T getEnum(String property, Class<T> type, T defaultValue)
T - The enum type.property - The property name.type - The enum type.defaultValue - The default value to return if the property is not presentpublic String getString(String property)
property - The property name.ConfigurationException - if the property is not presentpublic String getString(String property, String defaultValue)
property - The property name.defaultValue - The default value to return if the property is not present.public boolean getBoolean(String property)
property - The property name.ConfigurationException - if the property is not presentpublic boolean getBoolean(String property, boolean defaultValue)
property - The property name.defaultValue - The default value to return if the property is not presentpublic short getShort(String property)
property - The property name.ConfigurationException - if the property is not presentpublic short getShort(String property, short defaultValue)
property - The property name.defaultValue - The default value to return if the property is not presentpublic int getInteger(String property)
property - The property name.ConfigurationException - if the property is not presentpublic int getInteger(String property, int defaultValue)
property - The property name.defaultValue - The default value to return if the property is not presentpublic long getLong(String property)
property - The property name.ConfigurationException - if the property is not presentpublic long getLong(String property, long defaultValue)
property - The property name.defaultValue - The default value to return if the property is not presentpublic float getFloat(String property)
property - The property name.ConfigurationException - if the property is not presentpublic float getFloat(String property, float defaultValue)
property - The property name.defaultValue - The default value to return if the property is not presentpublic double getDouble(String property)
property - The property name.ConfigurationException - if the property is not presentpublic double getDouble(String property, double defaultValue)
property - The property name.defaultValue - The default value to return if the property is not presentpublic Duration getDuration(String property)
property - The property name.ConfigurationException - if the property is not presentCopyright © 2013–2016. All rights reserved.