Package groovy.util
Class ConfigObject
java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.util.ConfigObject
- All Implemented Interfaces:
- GroovyObject,- Writable,- Cloneable,- Map
A ConfigObject at a simple level is a Map that creates configuration entries (other ConfigObjects) when referencing them.
 This means that navigating to foo.bar.stuff will not return null but nested ConfigObjects which are of course empty maps
 The Groovy truth can be used to check for the existence of "real" entries.
- Since:
- 1.5
- 
Nested Class Summary
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidclear()clone()Returns a shallow copy of this ConfigObject, keys and configuration entries are not cloned.booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()flatten()A ConfigObject is a tree structure consisting of nested maps.Flattens this ConfigObject populating the results into the target MapgetProperty(String name) Overrides the default getProperty implementation to create nested ConfigObject instances on demand for non-existent keysbooleanisEmpty()Checks if a config option is set.keySet()merge(ConfigObject other) Merges the given map with this ConfigObject overriding any matching configuration entries in this ConfigObjectvoidvoidsetConfigFile(URL configFile) intsize()Converts this ConfigObject into the java.util.Properties format, flattening the tree structure beforehandtoProperties(String prefix) Converts this ConfigObject ino the java.util.Properties format, flatten the tree and prefixing all entries with the given prefixtoString()values()Writes this config object into a String serialized representation which can later be parsed back using the parse() methodMethods inherited from class groovy.lang.GroovyObjectSupportgetMetaClass, setMetaClassMethods inherited from class java.lang.Objectequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface groovy.lang.GroovyObjectinvokeMethod, setPropertyMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Constructor Details- 
ConfigObject
- 
ConfigObjectpublic ConfigObject()
 
- 
- 
Method Details- 
getConfigFile
- 
setConfigFile
- 
writeToWrites this config object into a String serialized representation which can later be parsed back using the parse() method- Specified by:
- writeToin interface- Writable
- Parameters:
- outArg- the Writer to which this Writable should output its data.
- Returns:
- the Writer that was passed
- Throws:
- IOException- if an error occurred while outputting data to the writer
- See Also:
 
- 
getPropertyOverrides the default getProperty implementation to create nested ConfigObject instances on demand for non-existent keys- Specified by:
- getPropertyin interface- GroovyObject
- Parameters:
- name- the name of the property of interest
- Returns:
- the given property
 
- 
flattenA ConfigObject is a tree structure consisting of nested maps. This flattens the maps into a single level structure like a properties file
- 
flattenFlattens this ConfigObject populating the results into the target Map- See Also:
 
- 
mergeMerges the given map with this ConfigObject overriding any matching configuration entries in this ConfigObject- Parameters:
- other- The ConfigObject to merge with
- Returns:
- The result of the merge
 
- 
toPropertiesConverts this ConfigObject into the java.util.Properties format, flattening the tree structure beforehand- Returns:
- A java.util.Properties instance
 
- 
toPropertiesConverts this ConfigObject ino the java.util.Properties format, flatten the tree and prefixing all entries with the given prefix- Parameters:
- prefix- The prefix to append before property entries
- Returns:
- A java.util.Properties instance
 
- 
sizepublic int size()
- 
isEmptypublic boolean isEmpty()
- 
containsKey- Specified by:
- containsKeyin interface- Map
 
- 
containsValue- Specified by:
- containsValuein interface- Map
 
- 
get
- 
put
- 
remove
- 
putAll
- 
clearpublic void clear()
- 
keySet
- 
values
- 
entrySet
- 
cloneReturns a shallow copy of this ConfigObject, keys and configuration entries are not cloned.
- 
isSetChecks if a config option is set. Example usage:def config = new ConfigSlurper().parse("foo { password='' }") assert config.foo.isSet('password') assert config.foo.isSet('username') == falseThe check works only for options one block below the current block. E.g.config.isSet('foo.password')will always return false.- Parameters:
- option- The name of the option
- Returns:
- trueif the option is set- falseotherwise
- Since:
- 2.3.0
 
- 
prettyPrint
- 
toString
 
-