Package groovy.util
Class ConfigObject
- java.lang.Object
- 
- groovy.lang.GroovyObjectSupport
- 
- groovy.util.ConfigObject
 
 
- 
- All Implemented Interfaces:
- GroovyObject,- Writable,- Cloneable,- Map
 
 public class ConfigObject extends GroovyObjectSupport implements Writable, Map, Cloneable 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
 
- 
- 
Constructor SummaryConstructors Constructor Description ConfigObject()ConfigObject(URL file)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()ConfigObjectclone()Returns a shallow copy of this ConfigObject, keys and configuration entries are not cloned.booleancontainsKey(Object key)booleancontainsValue(Object value)SetentrySet()Mapflatten()A ConfigObject is a tree structure consisting of nested maps.Mapflatten(Map target)Flattens this ConfigObject populating the results into the target MapObjectget(Object key)URLgetConfigFile()ObjectgetProperty(String name)Overrides the default getProperty implementation to create nested ConfigObject instances on demand for non-existent keysbooleanisEmpty()BooleanisSet(String option)Checks if a config option is set.SetkeySet()Mapmerge(ConfigObject other)Merges the given map with this ConfigObject overriding any matching configuration entries in this ConfigObjectStringprettyPrint()Objectput(Object key, Object value)voidputAll(Map m)Objectremove(Object key)voidsetConfigFile(URL configFile)intsize()PropertiestoProperties()Converts this ConfigObject into a the java.util.Properties format, flattening the tree structure beforehandPropertiestoProperties(String prefix)Converts this ConfigObject ino the java.util.Properties format, flatten the tree and prefixing all entries with the given prefixStringtoString()Collectionvalues()WriterwriteTo(Writer outArg)Writes this config object into a String serialized representation which can later be parsed back using the parse() method- 
Methods inherited from class groovy.lang.GroovyObjectSupportgetMetaClass, setMetaClass
 - 
Methods inherited from class java.lang.Objectequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface groovy.lang.GroovyObjectinvokeMethod, setProperty
 - 
Methods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
 
- 
 
- 
- 
- 
Constructor Detail- 
ConfigObjectpublic ConfigObject(URL file) 
 - 
ConfigObjectpublic ConfigObject() 
 
- 
 - 
Method Detail- 
getConfigFilepublic URL getConfigFile() 
 - 
setConfigFilepublic void setConfigFile(URL configFile) 
 - 
writeTopublic Writer writeTo(Writer outArg) throws IOException Writes 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:
- Writable.writeTo(java.io.Writer)
 
 - 
getPropertypublic Object getProperty(String name) Overrides 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
 
 - 
flattenpublic Map flatten() A ConfigObject is a tree structure consisting of nested maps. This flattens the maps into a single level structure like a properties file
 - 
flattenpublic Map flatten(Map target) Flattens this ConfigObject populating the results into the target Map- See Also:
- flatten()
 
 - 
mergepublic Map merge(ConfigObject other) Merges 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
 
 - 
toPropertiespublic Properties toProperties() Converts this ConfigObject into a the java.util.Properties format, flattening the tree structure beforehand- Returns:
- A java.util.Properties instance
 
 - 
toPropertiespublic Properties toProperties(String prefix) Converts 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
 
 - 
containsKeypublic boolean containsKey(Object key) - Specified by:
- containsKeyin interface- Map
 
 - 
containsValuepublic boolean containsValue(Object value) - Specified by:
- containsValuein interface- Map
 
 - 
valuespublic Collection values() 
 - 
clonepublic ConfigObject clone() Returns a shallow copy of this ConfigObject, keys and configuration entries are not cloned.
 - 
isSetpublic Boolean isSet(String option) Checks 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
 
 - 
prettyPrintpublic String prettyPrint() 
 
- 
 
-