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

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface java.util.Map

  `Map.Entry<K extends Object,V extends Object>`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ConfigObject()`
  Creates an empty config object with no associated source.
  `ConfigObject(URL file)`
  Creates a config object associated with the supplied source.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  `ConfigObject`
  `clone()`
  Returns a shallow copy of this ConfigObject, keys and configuration entries are not cloned.
  `boolean`
  `containsKey(Object key)`
  `boolean`
  `containsValue(Object value)`
  `Set`
  `entrySet()`
  `Map`
  `flatten()`
  A ConfigObject is a tree structure consisting of nested maps.
  `Map`
  `flatten(Map target)`
  Flattens this ConfigObject populating the results into the target Map
  `Object`
  `get(Object key)`
  `URL`
  `getConfigFile()`
  Returns the config resource that produced this object.
  `Object`
  `getProperty(String name)`
  Overrides the default getProperty implementation to create nested ConfigObject instances on demand for non-existent keys
  `boolean`
  `isEmpty()`
  `Boolean`
  `isSet(String option)`
  Checks if a config option is set.
  `Set`
  `keySet()`
  `Map`
  `merge(ConfigObject other)`
  Merges the given map with this ConfigObject overriding any matching configuration entries in this ConfigObject
  `String`
  `prettyPrint()`
  Renders this config object using config-script syntax.
  `Object`
  `put(Object key, Object value)`
  `void`
  `putAll(Map m)`
  `Object`
  `remove(Object key)`
  `void`
  `setConfigFile(URL configFile)`
  Updates the config resource associated with this object.
  `int`
  `size()`
  `Properties`
  `toProperties()`
  Converts this ConfigObject into the java.util.Properties format, flattening the tree structure beforehand
  `Properties`
  `toProperties(String prefix)`
  Converts this ConfigObject ino the java.util.Properties format, flatten the tree and prefixing all entries with the given prefix
  `String`
  `toString()`
  `Collection`
  `values()`
  `Writer`
  `writeTo(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.GroovyObjectSupport

  `getMetaClass, setMetaClass`

  ### Methods inherited from class java.lang.Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface groovy.lang.GroovyObject

  `invokeMethod, setProperty`

  ### Methods inherited from interface java.util.Map

  `compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll`

- ## Constructor Details

  - ### ConfigObject

    public ConfigObject(URL file)
    Creates a config object associated with the supplied source.
    Parameters:
      `file` - the parsed config resource, or `null`

  - ### ConfigObject

    public ConfigObject()
    Creates an empty config object with no associated source.

- ## Method Details

  - ### getConfigFile

    public URL getConfigFile()
    Returns the config resource that produced this object.
    Returns:
      the originating config resource, or `null`

  - ### setConfigFile

    public void setConfigFile(URL configFile)
    Updates the config resource associated with this object.
    Parameters:
      `configFile` - the originating config resource

  - ### writeTo

    public 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:
      `writeTo` in 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)`

  - ### getProperty

    public Object getProperty(String name)
    Overrides the default getProperty implementation to create nested ConfigObject instances on demand for non-existent keys
    Specified by:
      `getProperty` in interface `GroovyObject`
    Parameters:
      `name` - the name of the property of interest
    Returns:
      the given property

  - ### flatten

    public 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

  - ### flatten

    public Map flatten(Map target)
    Flattens this ConfigObject populating the results into the target Map
    See Also:
      - `flatten()`

  - ### merge

    public 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

  - ### toProperties

    public Properties toProperties()
    Converts this ConfigObject into the java.util.Properties format, flattening the tree structure beforehand
    Returns:
      A java.util.Properties instance

  - ### toProperties

    public 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

  - ### size

    public int size()
    Specified by:
      `size` in interface `Map`

  - ### isEmpty

    public boolean isEmpty()
    Specified by:
      `isEmpty` in interface `Map`

  - ### containsKey

    public boolean containsKey(Object key)
    Specified by:
      `containsKey` in interface `Map`

  - ### containsValue

    public boolean containsValue(Object value)
    Specified by:
      `containsValue` in interface `Map`

  - ### get

    public Object get(Object key)
    Specified by:
      `get` in interface `Map`

  - ### put

    public Object put(Object key, Object value)
    Specified by:
      `put` in interface `Map`

  - ### remove

    public Object remove(Object key)
    Specified by:
      `remove` in interface `Map`

  - ### putAll

    public void putAll(Map m)
    Specified by:
      `putAll` in interface `Map`

  - ### clear

    public void clear()
    Specified by:
      `clear` in interface `Map`

  - ### keySet

    public Set keySet()
    Specified by:
      `keySet` in interface `Map`

  - ### values

    public Collection values()
    Specified by:
      `values` in interface `Map`

  - ### entrySet

    public Set entrySet()
    Specified by:
      `entrySet` in interface `Map`

  - ### clone

    public ConfigObject clone()
    Returns a shallow copy of this ConfigObject, keys and configuration entries are not cloned.
    Overrides:
      `clone` in class `Object`
    Returns:
      a shallow copy of this ConfigObject

  - ### isSet

    public 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') == false

    The 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:
      `true` if the option is set `false` otherwise
    Since:
      2.3.0

  - ### prettyPrint

    public String prettyPrint()
    Renders this config object using config-script syntax.
    Returns:
      a formatted config representation

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`