[Java] Class ConfigObject
- groovy.util.ConfigObject
public class ConfigObject extends GroovyObjectSupport
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.
- Authors:
- Graeme Rocher
- Guillaume Laforge (rewrite in Java related to security constraints on Google App Engine)
- Since:
- 1.5
Constructor Summary
Constructor and description |
---|
ConfigObject
(URL file) |
ConfigObject
() |
Methods Summary
Type Params | Return Type | Name and 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() | |
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() | |
Object |
put(Object key, Object value) | |
void |
putAll(Map m) | |
Object |
remove(Object key) | |
void |
setConfigFile(URL configFile) | |
int |
size() | |
Properties |
toProperties() Converts this ConfigObject into a 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 |
Inherited Methods Summary
Methods inherited from class | Name |
---|---|
class GroovyObjectSupport | getMetaClass, getProperty, invokeMethod, setMetaClass, setProperty |
class Object | wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Constructor Detail
public ConfigObject(URL file)
public ConfigObject()
Method Detail
public void clear()
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)
public boolean containsValue(Object value)
public Set entrySet()
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)
public URL getConfigFile()
public Object getProperty(String name)
Overrides the default getProperty implementation to create nested ConfigObject instances on demand for non-existent keys
public boolean isEmpty()
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') == 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:
-
true
if the option is setfalse
otherwise
- Since:
- 2.3.0
public Set keySet()
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()
public Object put(Object key, Object value)
public void putAll(Map m)
public Object remove(Object key)
public void setConfigFile(URL configFile)
public int size()
public Properties toProperties()
Converts this ConfigObject into a 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
@Override public String toString()
public Collection values()
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
© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/2.4.21/html/gapi/groovy/util/ConfigObject.html