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 aConfigObjectwith the given data. -
Method Summary
Modifier and TypeMethodDescriptionclone()Returns a clone of thisConfigObject, which contains the same elements as thisConfigObject.booleancontainsKey(Object key) Returns whether the given key exists in thisConfigObject.booleancontainsValue(Object value) Returns whether the given value exists in thisConfigObject.copyData()Creates a newHashMapwith all values of thisConfigObject.entrySet()Returns an unmodifiable set of all entries in thisConfigObject.booleanDetermines whether the given object is equal to thisConfigObject.Returns a value associated with the given key in thisConfigObject, ornullif the given key has no value set.Returns aConfigArrayassociated with the given key in thisConfigObject.booleangetBoolean(String key) Returns abooleanassociated with the given key in thisConfigObject.doubleReturns adoubleassociated with the given key in thisConfigObject.floatReturns afloatassociated with the given key in thisConfigObject.intReturns anintassociated with the given key in thisConfigObject.longReturns alongassociated with the given key in thisConfigObject.Returns aConfigObjectassociated with the given key in thisConfigObject.Returns aStringassociated with the given key in thisConfigObject.inthashCode()Returns a hash code for thisConfigObject.booleanisEmpty()Returnstrueif thisConfigObjectcontains no key-value pairs.keySet()Returns an unmodifiable set of all keys of thisConfigObject.merge(ConfigObject other) Creates a newConfigObjectthat contains all properties of this and the givenConfigObject.Returns aConfigArrayassociated with the given key in thisConfigObject, ornullif no mapping the the given key exists or is not aConfigArray.booleanoptBoolean(String key, boolean def) Returns abooleanassociated with the given key in thisConfigObject, or def if no mapping the the given key exists or is not aboolean.doubleReturns adoubleassociated with the given key in thisConfigObject, or def if no mapping the the given key exists or is not adouble.floatReturns afloatassociated with the given key in thisConfigObject, or def if no mapping the the given key exists or is not afloat.intReturns anintassociated with the given key in thisConfigObject, or def if no mapping the the given key exists or is not anint.longReturns alongassociated with the given key in thisConfigObject, or def if no mapping the the given key exists or is not along.Returns aConfigObjectassociated with the given key in thisConfigObject, ornullif no mapping the the given key exists or is not aConfigObject.Returns aStringassociated with the given key in thisConfigObject, or def if no mapping the the given key exists or is not aString.voidpopulateConfigurationOptions(Object targetObject) Populates all fields with theConfigurationOptionannotation of the giventargetObjectwith values from thisConfigObjectusing reflection.intsize()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 aConfigObjectwith 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()Returnstrueif thisConfigObjectcontains no key-value pairs.- Returns:
trueif empty- See Also:
-
containsKey
Returns whether the given key exists in thisConfigObject.- Parameters:
key- The key to search for- Returns:
trueif the key exists- See Also:
-
containsValue
Returns whether the given value exists in thisConfigObject.- Parameters:
value- The value to search for- Returns:
trueif 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 newHashMapwith all values of thisConfigObject. Changes to the returned map have no effect on thisConfigObject.- Returns:
- A
Mapwith all values of thisConfigObject
-
merge
Creates a newConfigObjectthat contains all properties of this and the givenConfigObject. If both have a property with the same key, the value of the property in the givenConfigObjectis put into the newConfigObject.
Both provided objects stay unchanged.- Parameters:
other- TheConfigObjectto merge this one with, possibly overriding values of thisConfigObject- Returns:
- A new
ConfigObjectwith values merged from this and other
-
get
Returns a value associated with the given key in thisConfigObject, ornullif the given key has no value set. Note that a return value ofnullmay 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 withgetthrow anIllegalArgumentExceptionif the value does not exist or is not the expected type, while the methods starting withoptreturnnullor the value passed to the def argument instead.- Parameters:
key- The key- Returns:
- The value mapped to the given key or
nullif no such value exists
-
getObject
Returns aConfigObjectassociated 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 aConfigArrayassociated 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 aStringassociated 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 anintassociated 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 alongassociated 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 afloatassociated 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 adoubleassociated 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 abooleanassociated 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 aConfigObjectassociated with the given key in thisConfigObject, ornullif no mapping the the given key exists or is not aConfigObject.- Parameters:
key- The key- Returns:
- The
ConfigObject, ornullif it does not exist
-
optArray
Returns aConfigArrayassociated with the given key in thisConfigObject, ornullif no mapping the the given key exists or is not aConfigArray.- Parameters:
key- The key- Returns:
- The
ConfigArray, ornullif it does not exist
-
optString
Returns aStringassociated 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 anintassociated 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 alongassociated 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 afloatassociated 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 adoubleassociated 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 abooleanassociated 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 theConfigurationOptionannotation of the giventargetObjectwith values from thisConfigObjectusing reflection.The name of the field is the key used in this
ConfigObjectto get the value. If a value in thisConfigObjectdoes not have the same (or similar) type of the corresponding field, aConfigurationExceptionis thrown. If no value for an option is present in thisConfigObject, aConfigurationExceptionis 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
ConfigObjectand 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.
-