Package groovy.util
Class ConfigObject
java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.util.ConfigObject
- All Implemented Interfaces:
- GroovyObject,- Writable,- java.lang.Cloneable,- java.util.Map
public class ConfigObject extends GroovyObjectSupport implements Writable, java.util.Map, java.lang.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
- 
Nested Class SummaryNested classes/interfaces inherited from interface java.util.Mapjava.util.Map.Entry<K extends java.lang.Object,V extends java.lang.Object>
- 
Constructor SummaryConstructors Constructor Description ConfigObject()ConfigObject(java.net.URL file)
- 
Method SummaryModifier and Type Method Description voidclear()ConfigObjectclone()Returns a shallow copy of this ConfigObject, keys and configuration entries are not cloned.booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.SetentrySet()java.util.Mapflatten()A ConfigObject is a tree structure consisting of nested maps.java.util.Mapflatten(java.util.Map target)Flattens this ConfigObject populating the results into the target Mapjava.lang.Objectget(java.lang.Object key)java.net.URLgetConfigFile()java.lang.ObjectgetProperty(java.lang.String name)Overrides the default getProperty implementation to create nested ConfigObject instances on demand for non-existent keysbooleanisEmpty()java.lang.BooleanisSet(java.lang.String option)Checks if a config option is set.java.util.SetkeySet()java.util.Mapmerge(ConfigObject other)Merges the given map with this ConfigObject overriding any matching configuration entries in this ConfigObjectjava.lang.StringprettyPrint()java.lang.Objectput(java.lang.Object key, java.lang.Object value)voidputAll(java.util.Map m)java.lang.Objectremove(java.lang.Object key)voidsetConfigFile(java.net.URL configFile)intsize()java.util.PropertiestoProperties()Converts this ConfigObject into a the java.util.Properties format, flattening the tree structure beforehandjava.util.PropertiestoProperties(java.lang.String prefix)Converts this ConfigObject ino the java.util.Properties format, flatten the tree and prefixing all entries with the given prefixjava.lang.StringtoString()java.util.Collectionvalues()java.io.WriterwriteTo(java.io.Writer outArg)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- 
ConfigObjectpublic ConfigObject(java.net.URL file)
- 
ConfigObjectpublic ConfigObject()
 
- 
- 
Method Details- 
getConfigFilepublic java.net.URL getConfigFile()
- 
setConfigFilepublic void setConfigFile(java.net.URL configFile)
- 
writeTopublic java.io.Writer writeTo(java.io.Writer outArg) throws java.io.IOExceptionWrites 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:
- java.io.IOException- if an error occurred while outputting data to the writer
- See Also:
- Writable.writeTo(java.io.Writer)
 
- 
getPropertypublic java.lang.Object getProperty(java.lang.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 java.util.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 java.util.Map flatten(java.util.Map target)Flattens this ConfigObject populating the results into the target Map- See Also:
- flatten()
 
- 
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
 
- 
toPropertiespublic java.util.Properties toProperties()Converts this ConfigObject into a the java.util.Properties format, flattening the tree structure beforehand- Returns:
- A java.util.Properties instance
 
- 
toPropertiespublic java.util.Properties toProperties(java.lang.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
 
- 
sizepublic int size()- Specified by:
- sizein interface- java.util.Map
 
- 
isEmptypublic boolean isEmpty()- Specified by:
- isEmptyin interface- java.util.Map
 
- 
containsKeypublic boolean containsKey(java.lang.Object key)- Specified by:
- containsKeyin interface- java.util.Map
 
- 
containsValuepublic boolean containsValue(java.lang.Object value)- Specified by:
- containsValuein interface- java.util.Map
 
- 
getpublic java.lang.Object get(java.lang.Object key)- Specified by:
- getin interface- java.util.Map
 
- 
putpublic java.lang.Object put(java.lang.Object key, java.lang.Object value)- Specified by:
- putin interface- java.util.Map
 
- 
removepublic java.lang.Object remove(java.lang.Object key)- Specified by:
- removein interface- java.util.Map
 
- 
putAllpublic void putAll(java.util.Map m)- Specified by:
- putAllin interface- java.util.Map
 
- 
clearpublic void clear()- Specified by:
- clearin interface- java.util.Map
 
- 
keySetpublic java.util.Set keySet()- Specified by:
- keySetin interface- java.util.Map
 
- 
valuespublic java.util.Collection values()- Specified by:
- valuesin interface- java.util.Map
 
- 
entrySetpublic java.util.Set entrySet()- Specified by:
- entrySetin interface- java.util.Map
 
- 
cloneReturns a shallow copy of this ConfigObject, keys and configuration entries are not cloned.- Overrides:
- clonein class- java.lang.Object
- Returns:
- a shallow copy of this ConfigObject
 
- 
isSetpublic java.lang.Boolean isSet(java.lang.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 java.lang.String prettyPrint()
- 
toStringpublic java.lang.String toString()- Overrides:
- toStringin class- java.lang.Object
 
 
-