public class EnhancedProperties extends Properties implements Copyable<EnhancedProperties>
Extends the java.util.Properties stuff to provide typed accessors to get property values as boolean, int, etc. Also provides a way to get a property value as a list, or as a map of values. And it does variable substitution on property values.
Given the following property file
some_boolean_property = true
some_integer_property = 42
some_property = some_value
some_list = one, two, three, four
some_other_property = ${some_property}/foo
some_map = key_a, key_b, key_c
key_a = a
key_b = b
key_c = c
getPropertyAsBoolean("some_boolean_property") yields the boolean value true.
getPropertyAsInt("some_integer_property") yields the integer 42.
getPropertyAsList("some_list") yields a List<String> with the values "one", "two", "three", "four".
getPropertyAsMap("some_map") yields a Map<String, String> with the key value pairs:
key_a => a, key_b => b, key_c => c. Lastly, getting the property "some_other_property" yields the value "some_value/foo" via
variable substitution.
defaults| Constructor and Description |
|---|
EnhancedProperties()
Create a new EnhancedProperties
|
EnhancedProperties(InputStream theInput)
Create a new EnhancedProperties
|
EnhancedProperties(Properties theProps)
Copy constructor
|
| Modifier and Type | Method and Description |
|---|---|
EnhancedProperties |
copy()
Create a deep copy of the object which does not share any references with the original.
|
String |
getProperty(String theProp)
Returns the value of the given property
|
boolean |
getPropertyAsBoolean(String theProp)
Return the value of the property as a boolean
|
boolean |
getPropertyAsBoolean(String theProperty,
boolean theDefault)
Return the value of the property as a boolean.
|
double |
getPropertyAsDouble(String theProperty)
Return the value of the property as a double
|
double |
getPropertyAsDouble(String theProperty,
double theDefault)
Return the value of the property as a double
|
float |
getPropertyAsFloat(String theProperty)
Return the value of the property as a float
|
float |
getPropertyAsFloat(String theProperty,
float theDefault)
Return the value of the property as a float
|
int |
getPropertyAsInt(String theProp)
Return the value of the property as an int
|
int |
getPropertyAsInt(String theProp,
int theDefault)
Return the value of the property as an int
|
List<String> |
getPropertyAsList(String theProp)
Returns the value of a property as a list.
|
long |
getPropertyAsLong(String theProperty)
Return the value of the property as a long
|
long |
getPropertyAsLong(String theProperty,
long theDefault)
Return the value of the property as a long
|
Map<String,String> |
getPropertyAsMap(String theProp)
Returns the value of the property as a map.
|
Iterable<EnhancedProperties> |
partitionByKeys(Function<String,String> thePartitionFunction) |
Object |
put(Object theKey,
Object theValue) |
EnhancedProperties |
select(Predicate<String> theKeySelector)
Return a subset of this Properties object by selecting all the keys which pass the predicate filter and
inserting those key-value objects into the returned value.
|
EnhancedProperties |
transformKeys(Function<String,String> theKeyFunction) |
EnhancedProperties |
transformValues(Function<String,String> theValueFunction) |
getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNamesclear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, merge, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, size, toString, valuespublic EnhancedProperties()
public EnhancedProperties(InputStream theInput) throws IOException
theInput - the inputstream to load property data fromIOException - thrown if there is an error reading properties datapublic EnhancedProperties(Properties theProps)
theProps - the properties to copy frompublic boolean getPropertyAsBoolean(String theProp)
theProp - the property to retrievepublic boolean getPropertyAsBoolean(String theProperty, boolean theDefault)
theProperty - the property to retrievetheDefault - the default value if the property does not existpublic String getProperty(String theProp)
getProperty in class PropertiestheProp - the property to retrievepublic int getPropertyAsInt(String theProp, int theDefault) throws NumberFormatException
theProp - the property to retrievetheDefault - the default property valueNumberFormatException - thrown if the value is not a valid integer valuepublic int getPropertyAsInt(String theProp) throws NumberFormatException
theProp - the property to retrieveNumberFormatException - thrown if the value is not a valid integer valuepublic long getPropertyAsLong(String theProperty, long theDefault) throws NumberFormatException
theProperty - the property to retrievetheDefault - the default value if the property does not existNumberFormatException - thrown if the value is not a value long valuepublic long getPropertyAsLong(String theProperty) throws NumberFormatException
theProperty - the property to retrieveNumberFormatException - thrown if the value is not a value long valuepublic float getPropertyAsFloat(String theProperty, float theDefault) throws NumberFormatException
theProperty - the property to retrievetheDefault - the default value to return if the property does not existNumberFormatException - thrown if the value is not a valid float valuepublic float getPropertyAsFloat(String theProperty) throws NumberFormatException
theProperty - the property to retrieveNumberFormatException - thrown if the value is not a valid float valuepublic double getPropertyAsDouble(String theProperty) throws NumberFormatException
theProperty - the property to retrieveNumberFormatException - thrown if the value is not a valid double valuepublic double getPropertyAsDouble(String theProperty, double theDefault) throws NumberFormatException
theProperty - the property to retrievetheDefault - the default value for the property if it does not existNumberFormatException - thrown if the value is not a valid double valuepublic List<String> getPropertyAsList(String theProp)
mylist = one, two, three, fourWould yield a list of four elements, "one", "two", "three" and "four".
theProp - the property keypublic Map<String,String> getPropertyAsMap(String theProp)
map = foo, baz, boz foo = bar baz = biz boz = buzzGetting the key "map" as a map will yield a map with three keys "foo", "baz", and "boz" with the values "bar", "biz" and "buzz" respectively. The keys of the map MUST be comma separated. If a key does not have a corresponding value, it is not added to the result map.
theProp - the property key which has the key values of the map as its valuepublic EnhancedProperties copy()
copy in interface Copyable<EnhancedProperties>public EnhancedProperties select(Predicate<String> theKeySelector)
theKeySelector - the filter for key valuespublic EnhancedProperties transformKeys(Function<String,String> theKeyFunction)
public EnhancedProperties transformValues(Function<String,String> theValueFunction)
public Iterable<EnhancedProperties> partitionByKeys(Function<String,String> thePartitionFunction)
Copyright © 2010-2016 Stardog Union. All Rights Reserved.