Package: groovy.util

## [Java] Class ConfigObject

- groovy.util.ConfigObject

- All Implemented Interfaces and Traits:
    Writable, Map, Cloneable

      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 Summary

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

  - ### Methods Summary

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

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class GroovyObjectSupport` | `getMetaClass, setMetaClass`

- - ### Constructor Detail

    - #### public ConfigObject(URL file)

      Creates a config object associated with the supplied source.

      Parameters:
        `file` - the parsed config resource, or `null`

    - #### public ConfigObject()

      Creates an empty config object with no associated source.

  - ### Method Detail

    - #### public void clear()

      {@inheritDoc}

    - #### public ConfigObject clone()

      Returns a shallow copy of this ConfigObject, keys and configuration entries are not cloned.

      Returns:
        a shallow copy of this ConfigObject

    - #### public boolean containsKey(Object key)

      {@inheritDoc}

    - #### public boolean containsValue(Object value)

      {@inheritDoc}

    - #### public Set entrySet()

      {@inheritDoc}

    - #### 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

    - #### public Map flatten(Map target)

      Flattens this ConfigObject populating the results into the target Map

      See Also:
        ConfigObject.flatten

    - #### public Object get(Object key)

      {@inheritDoc}

    - #### public URL getConfigFile()

      Returns the config resource that produced this object.

      Returns:
        the originating config resource, or `null`

    - #### public Object getProperty(String name)

      Overrides the default getProperty implementation to create nested ConfigObject instances on demand for non-existent keys

    - #### public boolean isEmpty()

      {@inheritDoc}

    - #### 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

    - #### public Set keySet()

      {@inheritDoc}

    - #### 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

    - #### public String prettyPrint()

      Renders this config object using config-script syntax.

      Returns:
        a formatted config representation

    - #### public Object put(Object key, Object value)

      {@inheritDoc}

    - #### public void putAll(Map m)

      {@inheritDoc}

    - #### public Object remove(Object key)

      {@inheritDoc}

    - #### public void setConfigFile(URL configFile)

      Updates the config resource associated with this object.

      Parameters:
        `configFile` - the originating config resource

    - #### public int size()

      {@inheritDoc}

    - #### public Properties toProperties()

      Converts this ConfigObject into the java.util.Properties format, flattening the tree structure beforehand

      Returns:
        A java.util.Properties instance

    - #### 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

    - #### public String toString()

      {@inheritDoc}

    - #### public Collection values()

      {@inheritDoc}

    - #### public Writer writeTo(Writer outArg)

      Writes this config object into a String serialized representation which can later be parsed back using the parse() method

      See Also:
        Writable.writeTo