Class Properties
- java.lang.Object
-
- com.norconex.commons.lang.map.ObservableMap<String,List<String>>
-
- com.norconex.commons.lang.map.Properties
-
- All Implemented Interfaces:
Serializable
,Map<String,List<String>>
- Direct Known Subclasses:
QueryString
public class Properties extends ObservableMap<String,List<String>> implements Serializable
This class is a enhanced version of
Properties
that enforces the use of String keys and values internally, but offers many convenience methods for storing and retrieving multiple values of different types (e.g. Integer, Locale, File, etc). It also supports properties with multiple values. You can also see this class as a string-based multi-value map with helpful methods. While it does not extendProperties
, it offers similar load and store methods and can be used as a replacement for it in many cases. It also adds support for storing/loading as JSON, XML, and Java Bean.This class extends
ObservableMap
which means you can listen for property changes.To insert values, there are set and add methods. The set methods will first remove any existing value(s) under the given key before inserting the new one(s). It is essentially the same behavior as
Map.put(Object, Object)
. The add method will add the new value(s) to the list of already existing ones (if any).The storing of entries with multiple values will create one file entry per value. To preserve old behavior and force multiple values to be on the same line, use the store/load method accepting a joining delimiter.
Upon encountering a problem in parsing a value to its desired type, a
PropertiesException
is thrown.- Author:
- Pascal Essiembre
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_JAVA_PROPERTIES_DELIMITER
-
Constructor Summary
Constructors Constructor Description Properties()
Create a new instance with case-sensitive keys.Properties(boolean caseInsensitiveKeys)
Creates a new instance.Properties(Map<String,List<String>> map)
DecoratesMap
as aProperties
.Properties(Map<String,List<String>> map, boolean caseInsensitiveKeys)
Decorates aMap
argument as aProperties
.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <T> void
add(String key, T... values)
Adds one or multiple string values.void
addBigDecimal(String key, BigDecimal... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
void
addBoolean(String key, boolean... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
void
addClass(String key, Class<?>... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
void
addDate(String key, Date... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
void
addDouble(String key, double... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
void
addFile(String key, File... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
void
addFloat(String key, float... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
void
addInt(String key, int... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
<T> void
addList(String key, List<T> values)
Adds one or multiple values as strings.void
addLocale(String key, Locale... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
void
addLong(String key, long... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
void
addString(String key, String... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
boolean
equals(Object other)
void
fromString(String str)
Reads a property list (key and element pairs) from the input string.List<String>
get(Object key)
<T> T
get(String key, Class<T> type)
Gets a single value, converted to the given type.<T> T
get(String key, Class<T> type, T defaultValue)
Gets a single value, converted to the given type.BigDecimal
getBigDecimal(String key)
Gets value as a BigDecimal.BigDecimal
getBigDecimal(String key, BigDecimal defaultValue)
Gets value as a BigDecimal.List<BigDecimal>
getBigDecimals(String key)
Gets values as a list of BigDecimals.Boolean
getBoolean(String key)
Gets value as a boolean.Boolean
getBoolean(String key, Boolean defaultValue)
Gets value as a boolean.List<Boolean>
getBooleans(String key)
Gets values as a list of booleans.Class<?>
getClass(String key)
Gets a class, assuming key value is a fully qualified class name available in the classloader.Class<?>
getClass(String key, Class<?> defaultValue)
Gets a class, assuming key value is a fully qualified class name available in the classloader.List<Class>
getClasses(String key)
Gets values as a list of initialized classes.Date
getDate(String key)
Gets value as a date.Date
getDate(String key, Date defaultValue)
Gets value as a date.List<Date>
getDates(String key)
Gets values as a list of dates.Double
getDouble(String key)
Gets value as a double.Double
getDouble(String key, Double defaultValue)
Gets value as a double.List<Double>
getDoubles(String key)
Gets values as a list of doubles.File
getFile(String key)
Gets a file, assuming key value is a file system path.File
getFile(String key, File defaultValue)
Gets a file, assuming key value is a file system path.List<File>
getFiles(String key)
Gets values as a list of files.Float
getFloat(String key)
Gets value as a float.Float
getFloat(String key, Float defaultValue)
Gets value as a float.List<Float>
getFloats(String key)
Gets values as a list of floats.Instant
getInstant(String key)
Gets value as a UTC date-timeInstant
.Instant
getInstant(String key, Instant defaultValue)
Gets value as a UTC date-timeInstant
.List<Instant>
getInstants(String key)
Gets values as a list of UTC date-timeInstant
s.Integer
getInteger(String key)
Gets value as an integer.Integer
getInteger(String key, Integer defaultValue)
Gets value as an integer.List<Integer>
getIntegers(String key)
Gets values as a list of integers.<T> List<T>
getList(String key, Class<T> type)
Gets a list of values, with its elements converted to the given type.<T> List<T>
getList(String key, Class<T> type, List<T> defaultValues)
Gets a list of values, with its elements converted to the given type.LocalDateTime
getLocalDateTime(String key)
Gets value as a local date-time.LocalDateTime
getLocalDateTime(String key, LocalDateTime defaultValue)
Gets value as a local date-time.List<LocalDateTime>
getLocalDateTimes(String key)
Gets values as a list of local date-times.Locale
getLocale(String key)
Gets value as a locale.Locale
getLocale(String key, Locale defaultValue)
Gets value as a locale.List<Locale>
getLocales(String key)
Gets values as a list of locales.Long
getLong(String key)
Gets value as a long.Long
getLong(String key, Long defaultValue)
Gets value as a long.List<Long>
getLongs(String key)
Gets values as a list of longs.String
getString(String key)
Gets value as string.String
getString(String key, String defaultValue)
Gets value as string.List<String>
getStrings(String key)
Gets values as a list of strings.int
hashCode()
boolean
isCaseInsensitiveKeys()
Gets whether keys are case sensitive or not.void
load(InputStream inStream)
Deprecated.Since 2.0.0, useloadFromProperties(...)
void
load(InputStream inStream, String encoding)
Deprecated.Since 2.0.0, useloadFromProperties(...)
void
load(InputStream inStream, String encoding, String delimiter)
Deprecated.Since 2.0.0, useloadFromProperties(...)
void
load(Reader reader)
Deprecated.Since 2.0.0, useloadFromProperties(...)
void
load(Reader reader, String delimiter)
Deprecated.Since 2.0.0, useloadFromProperties(...)
void
loadFromBean(Object bean)
Converts all the bean properties into entries in this instance.void
loadFromJSON(InputStream in)
Loads all of the properties from the JSON document input stream (UTF-8) into this instance.void
loadFromJSON(Reader reader)
Loads all of the properties from the JSON document reader into this instance.void
loadFromMap(Map<?,?> map)
Reads all key/value pairs in the given map, and add them to thisMap
.void
loadFromProperties(InputStream inStream)
Loads thisMap
from an input of a format compatible withProperties.load(InputStream)
.void
loadFromProperties(InputStream inStream, String delimiter)
Loads thisMap
from an input of a format compatible withProperties.load(InputStream)
.void
loadFromProperties(Reader reader)
Loads thisMap
from an input of a format compatible withProperties.load(Reader)
.void
loadFromProperties(Reader reader, String delimiter)
Loads thisMap
from an input of a format compatible withProperties.load(Reader)
.void
loadFromXML(InputStream in)
Loads thisMap
from an input of a format compatible withProperties.loadFromXML(InputStream)
.void
loadFromXML(InputStream in, String delimiter)
Loads thisMap
from an input of a format compatible withProperties.load(InputStream)
.void
loadFromXML(Reader reader)
Loads thisMap
from an input of a format compatible withProperties.loadFromXML(InputStream)
.void
loadFromXML(Reader reader, String delimiter)
Loads thisMap
from an input of a format compatible withProperties.load(InputStream)
.Properties
match(PropertyMatcher propertyMatcher)
Gets a properties subset for keys and values matched by the property matcher.Properties
match(TextMatcher fieldMatcher, TextMatcher valueMatcher)
Gets a properties subset for matching keys and values.Properties
matchKeys(TextMatcher keyMatcher)
Gets a properties subset for keys matched by the key matcher.Properties
matchValues(TextMatcher valueMatcher)
Gets a properties subset for values matched by the value matcher.List<String>
put(String key, List<String> values)
void
putAll(Map<? extends String,? extends List<String>> m)
List<String>
remove(Object key)
<T> void
set(String key, T... values)
Sets one or multiple values as strings replacing existing ones.void
setBigDecimal(String key, BigDecimal... values)
Deprecated.Since 2.0.0, useset(String, Object...)
void
setBoolean(String key, boolean... values)
Deprecated.Since 2.0.0, useset(String, Object...)
void
setClass(String key, Class<?>... values)
Deprecated.Since 2.0.0, useset(String, Object...)
void
setDate(String key, Date... values)
Deprecated.Since 2.0.0, useset(String, Object...)
void
setDouble(String key, double... values)
Deprecated.Since 2.0.0, useset(String, Object...)
void
setFile(String key, File... values)
Deprecated.Since 2.0.0, useset(String, Object...)
void
setFloat(String key, float... values)
Deprecated.Since 2.0.0, useset(String, Object...)
void
setInt(String key, int... values)
Deprecated.Since 2.0.0, useset(String, Object...)
<T> void
setList(String key, List<T> values)
Sets one or multiple values as strings replacing existing ones.void
setLocale(String key, Locale... values)
Deprecated.Since 2.0.0, useset(String, Object...)
void
setLong(String key, long... values)
Deprecated.Since 2.0.0, useset(String, Object...)
void
setString(String key, String... values)
Deprecated.Since 2.0.0, useset(String, Object...)
void
store(OutputStream out)
Deprecated.Since 2.0.0, usestoreToProperties(...)
void
store(OutputStream out, String comments)
Deprecated.Since 2.0.0, usestoreToProperties(...)
void
store(OutputStream out, String comments, String delimiter)
Deprecated.Since 2.0.0, usestoreToProperties(...)
void
store(Writer writer)
Deprecated.Since 2.0.0, usestoreToProperties(...)
void
store(Writer writer, String comments)
Deprecated.Since 2.0.0, usestoreToProperties(...)
void
store(Writer writer, String comments, String delimiter)
Deprecated.Since 2.0.0, usestoreToProperties(...)
void
storeToBean(Object bean)
Copy all properties in this map to the given bean, mapping keys to setter methods of the same name.void
storeToJSON(OutputStream os)
Writes thisMap
as JSON to the output stream as UTF-8 in a format suitable for using theloadFromJSON(InputStream)
method.void
storeToJSON(Writer writer)
Writes thisMap
as JSON to the writer in a format suitable for using theloadFromJSON(Reader)
method.void
storeToProperties(OutputStream out)
Stores thisMap
in a format compatible withProperties.store(OutputStream, String)
.void
storeToProperties(OutputStream out, String delimiter)
Stores thisMap
in a format compatible withProperties.store(OutputStream, String)
.void
storeToProperties(Writer writer)
Stores thisMap
in a format compatible withProperties.store(Writer, String)
.void
storeToProperties(Writer writer, String delimiter)
Stores thisMap
in a format compatible withProperties.store(Writer, String)
.void
storeToXML(OutputStream os)
Stores thisMap
in a UTF-8 format compatible withProperties.storeToXML(OutputStream, String)
.void
storeToXML(OutputStream os, String delimiter)
Stores thisMap
in a UTF-8 format compatible withProperties.storeToXML(OutputStream, String)
.void
storeToXML(Writer writer)
Stores thisMap
in a UTF-8 format compatible withProperties.storeToXML(OutputStream, String)
.void
storeToXML(Writer writer, String delimiter)
Stores thisMap
in a UTF-8 format compatible withProperties.storeToXML(OutputStream, String)
.Properties
toProperties()
Converts thisMap
to a new JavaProperties
instance.String
toString()
Returns thisMap
in a format compatible withProperties.store(Writer, String)
.List<String>
valueList()
Returns all property values merged into a single list.-
Methods inherited from class com.norconex.commons.lang.map.ObservableMap
addMapChangeListener, clear, containsKey, containsValue, entrySet, isEmpty, keySet, removeMapChangeListener, size, values
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Field Detail
-
DEFAULT_JAVA_PROPERTIES_DELIMITER
public static final String DEFAULT_JAVA_PROPERTIES_DELIMITER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Properties
public Properties()
Create a new instance with case-sensitive keys. Internally wraps aHashMap
to store keys and values.
-
Properties
public Properties(boolean caseInsensitiveKeys)
Creates a new instance. Internally wraps aHashMap
to store keys and values.- Parameters:
caseInsensitiveKeys
- whentrue
methods taking a key argument will consider the key being passed without consideration for character case.
-
Properties
public Properties(Map<String,List<String>> map)
DecoratesMap
as aProperties
. As of version 1.4 theMap
argument is decorated so that modifications to this instance will also modify the suppliedMap
. To use aMap
to initialize values only, use theloadFromMap(Map)
method.- Parameters:
map
- the Map to decorate
-
Properties
public Properties(Map<String,List<String>> map, boolean caseInsensitiveKeys)
Decorates aMap
argument as aProperties
. As of version 1.4 theMap
argument is decorated so that modifications to this instance will also modify the suppliedMap
. To use aMap
to initialize values only, use theloadFromMap(Map)
method.- Parameters:
map
- the Map to decoratecaseInsensitiveKeys
- whentrue
methods taking a key argument will consider the key being passed without consideration for character case.
-
-
Method Detail
-
isCaseInsensitiveKeys
public boolean isCaseInsensitiveKeys()
Gets whether keys are case sensitive or not.- Returns:
true
if case insensitive- Since:
- 1.8
-
matchKeys
public Properties matchKeys(TextMatcher keyMatcher)
Gets a properties subset for keys matched by the key matcher.- Parameters:
keyMatcher
- keys to match- Returns:
- properties subset or empty properties (never
null
) - Since:
- 2.0.0
-
matchValues
public Properties matchValues(TextMatcher valueMatcher)
Gets a properties subset for values matched by the value matcher.- Parameters:
valueMatcher
- values to match- Returns:
- properties subset or empty properties (never
null
) - Since:
- 2.0.0
-
match
public Properties match(PropertyMatcher propertyMatcher)
Gets a properties subset for keys and values matched by the property matcher. Same as invokingmatch(TextMatcher, TextMatcher)
.- Parameters:
propertyMatcher
- property matcher- Returns:
- properties subset or empty properties (never
null
) - Since:
- 2.0.0
-
match
public Properties match(TextMatcher fieldMatcher, TextMatcher valueMatcher)
Gets a properties subset for matching keys and values. Same as invokingmatch(PropertyMatcher)
.- Parameters:
fieldMatcher
- property matchervalueMatcher
- property value- Returns:
- properties subset or empty properties (never
null
) - Since:
- 2.0.0
-
toString
public String toString()
Returns thisMap
in a format compatible withProperties.store(Writer, String)
. Multi-value properties are merged, joined by the symbol for record separator (U+241E).- Overrides:
toString
in classObservableMap<String,List<String>>
- Returns:
- the properties as string
- Since:
- 2.0.0
-
storeToProperties
public void storeToProperties(Writer writer) throws IOException
Stores thisMap
in a format compatible withProperties.store(Writer, String)
. Multi-value properties are merged, joined by the symbol for record separator (U+241E).- Parameters:
writer
- an output character stream writer.- Throws:
IOException
- i/o problem- Since:
- 2.0.0
-
storeToProperties
public void storeToProperties(Writer writer, String delimiter) throws IOException
Stores thisMap
in a format compatible withProperties.store(Writer, String)
. Multi-value properties are merged, joined by the supplied delimiter character. If the delimiter isnull
, the symbol for record separator (U+241E) is used.- Parameters:
writer
- an output character stream writer.delimiter
- string to used as a separator when joining multiple values for the same key.- Throws:
IOException
- i/o problem- Since:
- 2.0.0
-
storeToProperties
public void storeToProperties(OutputStream out) throws IOException
Stores thisMap
in a format compatible withProperties.store(OutputStream, String)
. Multi-value properties are merged, joined by the symbol for record separator (U+241E).- Parameters:
out
- an output stream.- Throws:
IOException
- i/o problem- Since:
- 2.0.0
-
storeToProperties
public void storeToProperties(OutputStream out, String delimiter) throws IOException
Stores thisMap
in a format compatible withProperties.store(OutputStream, String)
. Multi-value properties are merged, joined by the supplied delimiter character. If the delimiter isnull
, the symbol for record separator (U+241E) is used.- Parameters:
out
- an output stream.delimiter
- delimiter string to used as a separator when joining multiple values for the same key.- Throws:
IOException
- i/o problem- Since:
- 2.0.0
-
storeToXML
public void storeToXML(OutputStream os) throws IOException
Stores thisMap
in a UTF-8 format compatible withProperties.storeToXML(OutputStream, String)
. Multi-value properties are merged, joined by the symbol for record separator (U+241E).- Parameters:
os
- the output stream on which to store the XML document.- Throws:
IOException
- i/o problem- Since:
- 1.14.0
-
storeToXML
public void storeToXML(OutputStream os, String delimiter) throws IOException
Stores thisMap
in a UTF-8 format compatible withProperties.storeToXML(OutputStream, String)
. Multi-value properties are merged, joined by the supplied delimiter character. If the delimiter isnull
, the symbol for record separator (U+241E) is used.- Parameters:
os
- the output stream on which to store the XML document.delimiter
- delimiter string to used as a separator when joining multiple values for the same key.- Throws:
IOException
- i/o problem- Since:
- 1.14.0
-
storeToXML
public void storeToXML(Writer writer) throws IOException
Stores thisMap
in a UTF-8 format compatible withProperties.storeToXML(OutputStream, String)
. Multi-value properties are merged, joined by the symbol for record separator (U+241E).- Parameters:
writer
- writer on which to store the XML document.- Throws:
IOException
- i/o problem- Since:
- 1.14.0
-
storeToXML
public void storeToXML(Writer writer, String delimiter) throws IOException
Stores thisMap
in a UTF-8 format compatible withProperties.storeToXML(OutputStream, String)
. Multi-value properties are merged, joined by the supplied delimiter character. If the delimiter isnull
, the symbol for record separator (U+241E) is used.- Parameters:
writer
- the writer on which to store the XML document.delimiter
- delimiter string to used as a separator when joining multiple values for the same key.- Throws:
IOException
- i/o problem
-
storeToJSON
public void storeToJSON(OutputStream os) throws IOException
Writes thisMap
as JSON to the output stream as UTF-8 in a format suitable for using theloadFromJSON(InputStream)
method.- Parameters:
os
- the output stream on which to store the properties.- Throws:
IOException
- i/o problem- Since:
- 1.14.0
-
storeToJSON
public void storeToJSON(Writer writer) throws IOException
Writes thisMap
as JSON to the writer in a format suitable for using theloadFromJSON(Reader)
method.- Parameters:
writer
- the writer on which to store the XML document.- Throws:
IOException
- i/o problem- Since:
- 1.14.0
-
storeToBean
public void storeToBean(Object bean)
Copy all properties in this map to the given bean, mapping keys to setter methods of the same name. Existing bean values for matching accessors are overwritten. Other values are left intact.null
beans are ignored.- Parameters:
bean
- the object to store properties into- Since:
- 2.0.0
-
fromString
public void fromString(String str)
Reads a property list (key and element pairs) from the input string. Otherwise, the same considerations asloadFromProperties(InputStream)
apply.- Parameters:
str
- the string to load
-
toProperties
public Properties toProperties()
Converts thisMap
to a new JavaProperties
instance. Multi-value properties are merged, joined by the symbol for record separator (U+241E).- Returns:
- a
java.util.Properties
instance - Since:
- 2.0.0
- See Also:
loadFromMap(Map)
-
loadFromMap
public void loadFromMap(Map<?,?> map)
Reads all key/value pairs in the given map, and add them to this
Map
. Keys and values are converted to strings using their toString() method, with exception of values being arrays or collections. In such case, the entry is considered a multi-value one and each value will be converted to individual strings.null
keys are ignored.null
values are converted to an empty string.Changes to this instance won't be reflected in the given
Map
. If you want otherwise, use invoke the constructor with aMap
argument.You can use this method to populate this
Map
from aProperties
.- Parameters:
map
- the map containing values to load- Since:
- 2.0.0
-
loadFromProperties
public void loadFromProperties(Reader reader) throws IOException
Loads thisMap
from an input of a format compatible withProperties.load(Reader)
. Multi-value properties are split using the symbol for record separator (U+241E).- Parameters:
reader
- the input character stream.- Throws:
IOException
- i/o problem- Since:
- 2.0.0
-
loadFromProperties
public void loadFromProperties(Reader reader, String delimiter) throws IOException
Loads thisMap
from an input of a format compatible withProperties.load(Reader)
. Multi-value properties are split using the supplied delimiter string. If the delimiter isnull
, the symbol for record separator (U+241E) is used.- Parameters:
reader
- the input character stream.delimiter
- delimiter string to used to parse a multi-value key.- Throws:
IOException
- i/o problem- Since:
- 2.0.0
-
loadFromProperties
public void loadFromProperties(InputStream inStream) throws IOException
Loads thisMap
from an input of a format compatible withProperties.load(InputStream)
. Multi-value properties are split using the symbol for record separator (U+241E).- Parameters:
inStream
- the input stream.- Throws:
IOException
- i/o problem- Since:
- 2.0.0
-
loadFromProperties
public void loadFromProperties(InputStream inStream, String delimiter) throws IOException
Loads thisMap
from an input of a format compatible withProperties.load(InputStream)
. Multi-value properties are split using the supplied delimiter string. If the delimiter isnull
, the symbol for record separator (U+241E) is used.- Parameters:
inStream
- the input stream.delimiter
- delimiter string to used to parse a multi value key.- Throws:
IOException
- i/o problem- Since:
- 2.0.0
-
loadFromXML
public void loadFromXML(InputStream in) throws IOException
Loads thisMap
from an input of a format compatible withProperties.loadFromXML(InputStream)
. Multi-value properties are split using the symbol for record separator (U+241E).- Parameters:
in
- in the input stream from which to read the XML document.- Throws:
IOException
- i/o problem
-
loadFromXML
public void loadFromXML(InputStream in, String delimiter) throws IOException
Loads thisMap
from an input of a format compatible withProperties.load(InputStream)
. Multi-value properties are split using the supplied delimiter string. If the delimiter isnull
, the symbol for record separator (U+241E) is used.- Parameters:
in
- in the input stream from which to read the XML document.delimiter
- delimiter string to used to parse a multi-value key.- Throws:
IOException
- i/o problem- Since:
- 1.14.0
-
loadFromXML
public void loadFromXML(Reader reader) throws IOException
Loads thisMap
from an input of a format compatible withProperties.loadFromXML(InputStream)
. Multi-value properties are split using the symbol for record separator (U+241E).- Parameters:
reader
- the reader from which to read the XML document.- Throws:
IOException
- i/o problem- Since:
- 1.14.0
-
loadFromXML
public void loadFromXML(Reader reader, String delimiter) throws IOException
Loads thisMap
from an input of a format compatible withProperties.load(InputStream)
. Multi-value properties are split using the supplied delimiter string. If the delimiter isnull
, the symbol for record separator (U+241E) is used.- Parameters:
reader
- reader from which to read the XML document.delimiter
- delimiter string to used to parse a multi-value key.- Throws:
IOException
- i/o problem- Since:
- 1.14.0
-
loadFromJSON
public void loadFromJSON(InputStream in) throws IOException
Loads all of the properties from the JSON document input stream (UTF-8) into this instance.- Parameters:
in
- the input stream from which to read the JSON document.- Throws:
IOException
- i/o problem- Since:
- 1.14.0
-
loadFromJSON
public void loadFromJSON(Reader reader) throws IOException
Loads all of the properties from the JSON document reader into this instance.- Parameters:
reader
- the reader from which to read the JSON document.- Throws:
IOException
- i/o problem- Since:
- 1.14.0
-
loadFromBean
public void loadFromBean(Object bean)
Converts all the bean properties into entries in this instance.null
beans are ignored.- Parameters:
bean
- the object to load properties from- Since:
- 2.0.0
-
get
public final <T> T get(String key, Class<T> type)
Gets a single value, converted to the given type.- Type Parameters:
T
- returned value type- Parameters:
key
- the key of the value to gettype
- target class of value- Returns:
- value
- Since:
- 2.0.0
-
get
public final <T> T get(String key, Class<T> type, T defaultValue)
Gets a single value, converted to the given type.- Type Parameters:
T
- returned value type- Parameters:
key
- the key of the value to gettype
- target class of valuedefaultValue
- default value if key has no value.- Returns:
- value
- Since:
- 2.0.0
-
getList
public final <T> List<T> getList(String key, Class<T> type)
Gets a list of values, with its elements converted to the given type.- Type Parameters:
T
- returned list type- Parameters:
key
- the key of the values to gettype
- target class of values- Returns:
- value list
- Since:
- 2.0.0
-
getList
public final <T> List<T> getList(String key, Class<T> type, List<T> defaultValues)
Gets a list of values, with its elements converted to the given type.- Type Parameters:
T
- returned list type- Parameters:
key
- the key of the values to gettype
- target class of valuesdefaultValues
- default values if the key returnsnull
or an empty list- Returns:
- value list
- Since:
- 2.0.0
-
set
@SafeVarargs public final <T> void set(String key, T... values)
Sets one or multiple values as strings replacing existing ones. Setting a singlenull
value or an empty array is the same as callingremove(Object)
with the same key. When setting multiple values,null
values are converted to empty strings.- Type Parameters:
T
- values type- Parameters:
key
- the key of the value to setvalues
- the values to set- Since:
- 2.0.0
-
add
@SafeVarargs public final <T> void add(String key, T... values)
Adds one or multiple string values. Adding a singlenull
value has no effect. When adding multiple values,null
values are converted to blank strings.- Type Parameters:
T
- values type- Parameters:
key
- the key of the value to setvalues
- the values to set- Since:
- 2.0.0
-
setList
public final <T> void setList(String key, List<T> values)
Sets one or multiple values as strings replacing existing ones. Setting a singlenull
value or an empty array is the same as callingremove(Object)
with the same key. When setting multiple values,null
values are converted to empty strings.- Type Parameters:
T
- values type- Parameters:
key
- the key of the value to setvalues
- the values to set- Since:
- 2.0.0
-
addList
public final <T> void addList(String key, List<T> values)
Adds one or multiple values as strings. Adding anull
list has no effect. When adding multiple values,null
values are converted to empty strings.- Type Parameters:
T
- values type- Parameters:
key
- the key of the value to setvalues
- the values to set- Since:
- 2.0.0
-
getString
public final String getString(String key)
Gets value as string.- Parameters:
key
- property key- Returns:
- the value
-
getString
public final String getString(String key, String defaultValue)
Gets value as string.- Parameters:
key
- property keydefaultValue
- default value to return when original value is null.- Returns:
- the value
-
getStrings
public final List<String> getStrings(String key)
Gets values as a list of strings. This method is null-safe. No matches returns an empty list.- Parameters:
key
- property key- Returns:
- the values
-
setString
@Deprecated public final void setString(String key, String... values)
Deprecated.Since 2.0.0, useset(String, Object...)
Sets one or multiple string values replacing existing ones. Setting a singlenull
value or an empty string array is the same as callingremove(Object)
with the same key. When setting multiple values,null
values are converted to blank strings.- Parameters:
key
- the key of the value to setvalues
- the values to set
-
addString
@Deprecated public final void addString(String key, String... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
Adds one or multiple string values. Adding a singlenull
value has no effect. When adding multiple values,null
values are converted to blank strings.- Parameters:
key
- the key of the value to setvalues
- the values to set
-
getInteger
public final Integer getInteger(String key)
Gets value as an integer.- Parameters:
key
- property key- Returns:
- the value
-
getInteger
public final Integer getInteger(String key, Integer defaultValue)
Gets value as an integer.- Parameters:
key
- property keydefaultValue
- default value to return when original value is null.- Returns:
- the value
-
getIntegers
public final List<Integer> getIntegers(String key)
Gets values as a list of integers.- Parameters:
key
- property key- Returns:
- the values
-
setInt
@Deprecated public final void setInt(String key, int... values)
Deprecated.Since 2.0.0, useset(String, Object...)
Sets one or multiple integer values, replacing existing ones.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
addInt
@Deprecated public final void addInt(String key, int... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
Adds one or multiple integer values values.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
getDouble
public final Double getDouble(String key)
Gets value as a double.- Parameters:
key
- property key- Returns:
- the value
-
getDouble
public final Double getDouble(String key, Double defaultValue)
Gets value as a double.- Parameters:
key
- property keydefaultValue
- default value to return when original value is null.- Returns:
- the value
-
getDoubles
public final List<Double> getDoubles(String key)
Gets values as a list of doubles.- Parameters:
key
- property key- Returns:
- the values
-
setDouble
@Deprecated public final void setDouble(String key, double... values)
Deprecated.Since 2.0.0, useset(String, Object...)
Sets one or multiple double values, replacing existing ones.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
addDouble
@Deprecated public final void addDouble(String key, double... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
Adds one or multiple double values.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
getLong
public final Long getLong(String key)
Gets value as a long.- Parameters:
key
- property key- Returns:
- the value
-
getLong
public final Long getLong(String key, Long defaultValue)
Gets value as a long.- Parameters:
key
- property keydefaultValue
- default value to return when original value is null.- Returns:
- the value
-
getLongs
public final List<Long> getLongs(String key)
Gets values as a list of longs.- Parameters:
key
- property key- Returns:
- the values
-
setLong
@Deprecated public final void setLong(String key, long... values)
Deprecated.Since 2.0.0, useset(String, Object...)
Sets one or multiple long values, replacing existing ones.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
addLong
@Deprecated public final void addLong(String key, long... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
Add one or multiple long values.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
getFloat
public final Float getFloat(String key)
Gets value as a float.- Parameters:
key
- property key- Returns:
- the value
-
getFloat
public final Float getFloat(String key, Float defaultValue)
Gets value as a float.- Parameters:
key
- property keydefaultValue
- default value to return when original value is null.- Returns:
- the value
-
getFloats
public final List<Float> getFloats(String key)
Gets values as a list of floats.- Parameters:
key
- property key- Returns:
- the values
-
setFloat
@Deprecated public final void setFloat(String key, float... values)
Deprecated.Since 2.0.0, useset(String, Object...)
Sets one or multiple float values, replacing existing ones.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
addFloat
@Deprecated public final void addFloat(String key, float... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
Adds one or multiple long values.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
getBigDecimal
public final BigDecimal getBigDecimal(String key)
Gets value as a BigDecimal.- Parameters:
key
- property key- Returns:
- the value
-
getBigDecimal
public final BigDecimal getBigDecimal(String key, BigDecimal defaultValue)
Gets value as a BigDecimal.- Parameters:
key
- property keydefaultValue
- default value to return when original value is null.- Returns:
- the value
-
getBigDecimals
public final List<BigDecimal> getBigDecimals(String key)
Gets values as a list of BigDecimals.- Parameters:
key
- property key- Returns:
- the values
-
setBigDecimal
@Deprecated public final void setBigDecimal(String key, BigDecimal... values)
Deprecated.Since 2.0.0, useset(String, Object...)
Sets one or multiple BigDecimal values, replacing existing ones.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
addBigDecimal
@Deprecated public final void addBigDecimal(String key, BigDecimal... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
Add one or multiple BigDecimal values.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
getLocalDateTime
public final LocalDateTime getLocalDateTime(String key)
Gets value as a local date-time. The date must be a valid date-time as defined byDateTimeFormatter.ISO_LOCAL_DATE_TIME
.- Parameters:
key
- property key- Returns:
- the value
- Since:
- 2.0.0
-
getLocalDateTime
public final LocalDateTime getLocalDateTime(String key, LocalDateTime defaultValue)
Gets value as a local date-time. The date must be a valid date-time as defined byDateTimeFormatter.ISO_LOCAL_DATE_TIME
.- Parameters:
key
- property keydefaultValue
- default value to return when original value is null.- Returns:
- the value
- Since:
- 2.0.0
-
getLocalDateTimes
public final List<LocalDateTime> getLocalDateTimes(String key)
Gets values as a list of local date-times. Each date must be a valid date-time as defined byDateTimeFormatter.ISO_LOCAL_DATE_TIME
.- Parameters:
key
- property key- Returns:
- the values
- Since:
- 2.0.0
-
getInstant
public final Instant getInstant(String key)
Gets value as a UTC date-timeInstant
. The date must be a valid date-time as defined byDateTimeFormatter.ISO_INSTANT
.- Parameters:
key
- property key- Returns:
- the value
- Since:
- 2.0.0
-
getInstant
public final Instant getInstant(String key, Instant defaultValue)
Gets value as a UTC date-timeInstant
. The date must be a valid date-time as defined byDateTimeFormatter.ISO_INSTANT
.- Parameters:
key
- property keydefaultValue
- default value to return when original value is null.- Returns:
- the value
- Since:
- 2.0.0
-
getInstants
public final List<Instant> getInstants(String key)
Gets values as a list of UTC date-timeInstant
s. Each date must be a valid date-time as defined byDateTimeFormatter.ISO_INSTANT
.- Parameters:
key
- property key- Returns:
- the values
- Since:
- 2.0.0
-
getDate
public final Date getDate(String key)
Gets value as a date.- Parameters:
key
- property key- Returns:
- the value
-
getDate
public final Date getDate(String key, Date defaultValue)
Gets value as a date.- Parameters:
key
- property keydefaultValue
- default value to return when original value is null.- Returns:
- the value
-
getDates
public final List<Date> getDates(String key)
Gets values as a list of dates.- Parameters:
key
- property key- Returns:
- the values
-
setDate
@Deprecated public final void setDate(String key, Date... values)
Deprecated.Since 2.0.0, useset(String, Object...)
Sets one or multiple date values, replacing existing ones.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
addDate
@Deprecated public final void addDate(String key, Date... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
Add one or multiple date values.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
getBoolean
public final Boolean getBoolean(String key)
Gets value as a boolean. The underlying string value matching the key must exist and equal "true" (ignoring case) to returntrue
. Any other value (includingnull
) will returnfalse
.- Parameters:
key
- property key- Returns:
- the value
-
getBoolean
public final Boolean getBoolean(String key, Boolean defaultValue)
Gets value as a boolean. The underlying string value matching the key must exist and equal "true" (ignoring case) to returntrue
. Any other value (includingnull
) will returnfalse
. If there are no entries for the given key, the default value is returned instead.- Parameters:
key
- property keydefaultValue
- default value to return when original value is null.- Returns:
- the value
-
getBooleans
public final List<Boolean> getBooleans(String key)
Gets values as a list of booleans.- Parameters:
key
- property key- Returns:
- the values
-
setBoolean
@Deprecated public final void setBoolean(String key, boolean... values)
Deprecated.Since 2.0.0, useset(String, Object...)
Sets one or multiple boolean values, replacing existing ones.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
addBoolean
@Deprecated public final void addBoolean(String key, boolean... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
Adds one or multiple boolean values.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
getLocale
public final Locale getLocale(String key)
Gets value as a locale.- Parameters:
key
- property key- Returns:
- the value
-
getLocale
public final Locale getLocale(String key, Locale defaultValue)
Gets value as a locale.- Parameters:
key
- property keydefaultValue
- default value to return when original value is null.- Returns:
- the value
-
getLocales
public final List<Locale> getLocales(String key)
Gets values as a list of locales.- Parameters:
key
- property key- Returns:
- the values
-
setLocale
@Deprecated public final void setLocale(String key, Locale... values)
Deprecated.Since 2.0.0, useset(String, Object...)
Sets one or multiple locale values, replacing existing ones.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
addLocale
@Deprecated public final void addLocale(String key, Locale... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
Adds one or multiple locale values.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
getFile
public final File getFile(String key)
Gets a file, assuming key value is a file system path.- Parameters:
key
- properties key- Returns:
- a File
-
getFile
public final File getFile(String key, File defaultValue)
Gets a file, assuming key value is a file system path.- Parameters:
key
- properties keydefaultValue
- default file being returned if no file has been defined for the given key in the properties.- Returns:
- a File
-
getFiles
public final List<File> getFiles(String key)
Gets values as a list of files.- Parameters:
key
- property key- Returns:
- the values
-
setFile
@Deprecated public final void setFile(String key, File... values)
Deprecated.Since 2.0.0, useset(String, Object...)
Sets one or multiple file values, replacing existing ones.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
addFile
@Deprecated public final void addFile(String key, File... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
Adds one or multiple file values.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
getClass
public final Class<?> getClass(String key)
Gets a class, assuming key value is a fully qualified class name available in the classloader.- Parameters:
key
- properties key- Returns:
- initialized class
-
getClass
public final Class<?> getClass(String key, Class<?> defaultValue)
Gets a class, assuming key value is a fully qualified class name available in the classloader.- Parameters:
key
- properties keydefaultValue
- default file being returned if no class has been defined for the given key in the properties.- Returns:
- initialized class
-
getClasses
public final List<Class> getClasses(String key)
Gets values as a list of initialized classes.- Parameters:
key
- property key- Returns:
- the values
-
setClass
@Deprecated public final void setClass(String key, Class<?>... values)
Deprecated.Since 2.0.0, useset(String, Object...)
Sets one or multiple class values, replacing existing ones.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
addClass
@Deprecated public final void addClass(String key, Class<?>... values)
Deprecated.Since 2.0.0, useadd(String, Object...)
Adds one or multiple class values.- Parameters:
key
- the key of the values to setvalues
- the values to set
-
valueList
public List<String> valueList()
Returns all property values merged into a single list. Duplicate values are kept.- Returns:
- value list (never
null
) - Since:
- 2.0.0
-
load
@Deprecated public void load(Reader reader) throws IOException
Deprecated.Since 2.0.0, useloadFromProperties(...)
Deprecated.- Parameters:
reader
- the input character stream.- Throws:
IOException
- i/o problem
-
load
@Deprecated public void load(Reader reader, String delimiter) throws IOException
Deprecated.Since 2.0.0, useloadFromProperties(...)
Deprecated.- Parameters:
reader
- the input character stream.delimiter
- delimiter string to used to parse a multi-value key.- Throws:
IOException
- i/o problem- See Also:
load(Reader)
-
load
@Deprecated public void load(InputStream inStream) throws IOException
Deprecated.Since 2.0.0, useloadFromProperties(...)
Deprecated.- Parameters:
inStream
- the input stream.- Throws:
IOException
- i/o problem- See Also:
load(InputStream)
-
load
@Deprecated public void load(InputStream inStream, String encoding) throws IOException
Deprecated.Since 2.0.0, useloadFromProperties(...)
Deprecated.- Parameters:
inStream
- the input stream.encoding
- delimiter string to used to parse a multi-value key.- Throws:
IOException
- i/o problem- See Also:
load(InputStream)
-
load
@Deprecated public void load(InputStream inStream, String encoding, String delimiter) throws IOException
Deprecated.Since 2.0.0, useloadFromProperties(...)
Deprecated.- Parameters:
inStream
- the input stream.encoding
- delimiter string to used to parse a multi-value key.delimiter
- delimiter string to used to parse a multi value key.- Throws:
IOException
- i/o problem- Since:
- 1.14.0
-
store
@Deprecated public void store(Writer writer) throws IOException
Deprecated.Since 2.0.0, usestoreToProperties(...)
Deprecated.- Parameters:
writer
- an output character stream writer.- Throws:
IOException
- i/o problem
-
store
@Deprecated public void store(Writer writer, String comments) throws IOException
Deprecated.Since 2.0.0, usestoreToProperties(...)
Deprecated.- Parameters:
writer
- an output character stream writer.comments
- a description of the property list.- Throws:
IOException
- i/o problem
-
store
@Deprecated public void store(Writer writer, String comments, String delimiter) throws IOException
Deprecated.Since 2.0.0, usestoreToProperties(...)
Deprecated.- Parameters:
writer
- an output character stream writer.comments
- a description of the property list.delimiter
- string to used as a separator when joining multiple values for the same key.- Throws:
IOException
- i/o problem
-
store
@Deprecated public void store(OutputStream out) throws IOException
Deprecated.Since 2.0.0, usestoreToProperties(...)
Deprecated.- Parameters:
out
- an output stream.- Throws:
IOException
- i/o problem
-
store
@Deprecated public void store(OutputStream out, String comments) throws IOException
Deprecated.Since 2.0.0, usestoreToProperties(...)
Deprecated.- Parameters:
out
- an output stream.comments
- a description of the property list.- Throws:
IOException
- i/o problem
-
store
@Deprecated public void store(OutputStream out, String comments, String delimiter) throws IOException
Deprecated.Since 2.0.0, usestoreToProperties(...)
Deprecated.- Parameters:
out
- an output stream.comments
- a description of the property list.delimiter
- delimiter string to used as a separator when joining multiple values for the same key.- Throws:
IOException
- i/o problem
-
equals
public boolean equals(Object other)
-
-