Class ConfigObject
- All Implemented Interfaces:
Serializable
Configuration
instance.- Since:
- 2.4
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates an emptyConfigObject
.ConfigObject
(Map<String, Object> data) Creates aConfigObject
with the given data. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a clone of thisConfigObject
, which contains the same elements as thisConfigObject
.boolean
containsKey
(Object key) Returns whether the given key exists in thisConfigObject
.boolean
containsValue
(Object value) Returns whether the given value exists in thisConfigObject
.copyData()
Creates a newHashMap
with all values of thisConfigObject
.entrySet()
Returns an unmodifiable set of all entries in thisConfigObject
.boolean
Determines whether the given object is equal to thisConfigObject
.Returns a value associated with the given key in thisConfigObject
, ornull
if the given key has no value set.Returns aConfigArray
associated with the given key in thisConfigObject
.boolean
getBoolean
(String key) Returns aboolean
associated with the given key in thisConfigObject
.double
Returns adouble
associated with the given key in thisConfigObject
.float
Returns afloat
associated with the given key in thisConfigObject
.int
Returns anint
associated with the given key in thisConfigObject
.long
Returns along
associated with the given key in thisConfigObject
.Returns aConfigObject
associated with the given key in thisConfigObject
.Returns aString
associated with the given key in thisConfigObject
.int
hashCode()
Returns a hash code for thisConfigObject
.boolean
isEmpty()
Returnstrue
if thisConfigObject
contains no key-value pairs.keySet()
Returns an unmodifiable set of all keys of thisConfigObject
.merge
(ConfigObject other) Creates a newConfigObject
that contains all properties of this and the givenConfigObject
.Returns aConfigArray
associated with the given key in thisConfigObject
, ornull
if no mapping the the given key exists or is not aConfigArray
.boolean
optBoolean
(String key, boolean def) Returns aboolean
associated with the given key in thisConfigObject
, or def if no mapping the the given key exists or is not aboolean
.double
Returns adouble
associated with the given key in thisConfigObject
, or def if no mapping the the given key exists or is not adouble
.float
Returns afloat
associated with the given key in thisConfigObject
, or def if no mapping the the given key exists or is not afloat
.int
Returns anint
associated with the given key in thisConfigObject
, or def if no mapping the the given key exists or is not anint
.long
Returns along
associated with the given key in thisConfigObject
, or def if no mapping the the given key exists or is not along
.Returns aConfigObject
associated with the given key in thisConfigObject
, ornull
if no mapping the the given key exists or is not aConfigObject
.Returns aString
associated with the given key in thisConfigObject
, or def if no mapping the the given key exists or is not aString
.void
populateConfigurationOptions
(Object targetObject) Populates all fields with theConfigurationOption
annotation of the giventargetObject
with values from thisConfigObject
using reflection.int
size()
Returns the number of key-value pairs in thisConfigObject
.toString()
Returns a string representation of thisConfigObject
.values()
Returns an unmodifiable collection of all values of thisConfigObject
.
-
Field Details
-
data
The data.
-
-
Constructor Details
-
ConfigObject
public ConfigObject()Creates an emptyConfigObject
. -
ConfigObject
Creates aConfigObject
with the given data.Changes on the given map have no effects on this
ConfigObject
.- Parameters:
data
- The data
-
-
Method Details
-
size
public int size()Returns the number of key-value pairs in thisConfigObject
.- Returns:
- The number of key-value pairs
- See Also:
-
isEmpty
public boolean isEmpty()Returnstrue
if thisConfigObject
contains no key-value pairs.- Returns:
true
if empty- See Also:
-
containsKey
Returns whether the given key exists in thisConfigObject
.- Parameters:
key
- The key to search for- Returns:
true
if the key exists- See Also:
-
containsValue
Returns whether the given value exists in thisConfigObject
.- Parameters:
value
- The value to search for- Returns:
true
if the value exists- See Also:
-
keySet
Returns an unmodifiable set of all keys of thisConfigObject
.- Returns:
- A set of all keys
-
values
Returns an unmodifiable collection of all values of thisConfigObject
.- Returns:
- A collection of all values
-
entrySet
Returns an unmodifiable set of all entries in thisConfigObject
.- Returns:
- A set of entries
-
copyData
Creates a newHashMap
with all values of thisConfigObject
. Changes to the returned map have no effect on thisConfigObject
.- Returns:
- A
Map
with all values of thisConfigObject
-
merge
Creates a newConfigObject
that contains all properties of this and the givenConfigObject
. If both have a property with the same key, the value of the property in the givenConfigObject
is put into the newConfigObject
.
Both provided objects stay unchanged.- Parameters:
other
- TheConfigObject
to merge this one with, possibly overriding values of thisConfigObject
- Returns:
- A new
ConfigObject
with values merged from this and other
-
get
Returns a value associated with the given key in thisConfigObject
, ornull
if the given key has no value set. Note that a return value ofnull
may also indicate that the given key is explicitly mapped tonull
.This method can be used to get a value of any type. To eliminate the need for type checking in the caller code, any of the
get*
andopt*
methods may be used instead. The name and return value of those methods indicates the type that is checked for. Corresponding methods in both groups are equivalent, except that the methods starting withget
throw anIllegalArgumentException
if the value does not exist or is not the expected type, while the methods starting withopt
returnnull
or the value passed to the def argument instead.- Parameters:
key
- The key- Returns:
- The value mapped to the given key or
null
if no such value exists
-
getObject
Returns aConfigObject
associated with the given key in thisConfigObject
.- Parameters:
key
- The key- Returns:
- The
ConfigObject
- Throws:
IllegalArgumentException
- If no mapping with the given key exists or is not aConfigObject
-
getArray
Returns aConfigArray
associated with the given key in thisConfigObject
.- Parameters:
key
- The key- Returns:
- The
ConfigArray
- Throws:
IllegalArgumentException
- If no mapping with the given key exists or is not aConfigArray
-
getString
Returns aString
associated with the given key in thisConfigObject
.- Parameters:
key
- The key- Returns:
- The
String
- Throws:
IllegalArgumentException
- If no mapping with the given key exists or is not aString
-
getInt
Returns anint
associated with the given key in thisConfigObject
.- Parameters:
key
- The key- Returns:
- The
int
- Throws:
IllegalArgumentException
- If no mapping with the given key exists or is not anint
-
getLong
Returns along
associated with the given key in thisConfigObject
.- Parameters:
key
- The key- Returns:
- The
long
- Throws:
IllegalArgumentException
- If no mapping with the given key exists or is not along
-
getFloat
Returns afloat
associated with the given key in thisConfigObject
.- Parameters:
key
- The key- Returns:
- The
float
- Throws:
IllegalArgumentException
- If no mapping with the given key exists or is not afloat
-
getDouble
Returns adouble
associated with the given key in thisConfigObject
.- Parameters:
key
- The key- Returns:
- The
double
- Throws:
IllegalArgumentException
- If no mapping with the given key exists or is not adouble
-
getBoolean
Returns aboolean
associated with the given key in thisConfigObject
.- Parameters:
key
- The key- Returns:
- The
boolean
- Throws:
IllegalArgumentException
- If no mapping with the given key exists or is not aboolean
-
optObject
Returns aConfigObject
associated with the given key in thisConfigObject
, ornull
if no mapping the the given key exists or is not aConfigObject
.- Parameters:
key
- The key- Returns:
- The
ConfigObject
, ornull
if it does not exist
-
optArray
Returns aConfigArray
associated with the given key in thisConfigObject
, ornull
if no mapping the the given key exists or is not aConfigArray
.- Parameters:
key
- The key- Returns:
- The
ConfigArray
, ornull
if it does not exist
-
optString
Returns aString
associated with the given key in thisConfigObject
, or def if no mapping the the given key exists or is not aString
.- Parameters:
key
- The keydef
- The default value- Returns:
- The
String
-
optInt
Returns anint
associated with the given key in thisConfigObject
, or def if no mapping the the given key exists or is not anint
.- Parameters:
key
- The keydef
- The default value- Returns:
- The
int
-
optLong
Returns along
associated with the given key in thisConfigObject
, or def if no mapping the the given key exists or is not along
.- Parameters:
key
- The keydef
- The default value- Returns:
- The
long
-
optFloat
Returns afloat
associated with the given key in thisConfigObject
, or def if no mapping the the given key exists or is not afloat
.- Parameters:
key
- The keydef
- The default value- Returns:
- The
float
-
optDouble
Returns adouble
associated with the given key in thisConfigObject
, or def if no mapping the the given key exists or is not adouble
.- Parameters:
key
- The keydef
- The default value- Returns:
- The
double
-
optBoolean
Returns aboolean
associated with the given key in thisConfigObject
, or def if no mapping the the given key exists or is not aboolean
.- Parameters:
key
- The keydef
- The default value- Returns:
- The
boolean
-
populateConfigurationOptions
Populates all fields with theConfigurationOption
annotation of the giventargetObject
with values from thisConfigObject
using reflection.The name of the field is the key used in this
ConfigObject
to get the value. If a value in thisConfigObject
does not have the same (or similar) type of the corresponding field, aConfigurationException
is thrown. If no value for an option is present in thisConfigObject
, aConfigurationException
is thrown for required options; field values of other options stay unchanged.This method supports the following field type: all primitive types and their boxed types,
String
,ConfigObject
,ConfigArray
,List
.- Parameters:
targetObject
- The target object- Throws:
ConfigurationException
- If a value has the incorrect type, or the value of a required option is missingConfigurationException
- If a reflective operation failsUnsupportedOperationException
- If a field type is unsupported- Since:
- 2.10
-
equals
Determines whether the given object is equal to thisConfigObject
.Another object is equal if it is also a
ConfigObject
and contains the same mappings. -
hashCode
public int hashCode()Returns a hash code for thisConfigObject
. -
clone
Returns a clone of thisConfigObject
, which contains the same elements as thisConfigObject
. -
toString
Returns a string representation of thisConfigObject
.
-