mirror of
https://github.com/lightbend/config.git
synced 2025-02-22 01:00:31 +08:00
rename Config.toObject to Config.root
This is clearer about what the object represents and how it relates to the Config. I didn't name it root() before because it might have implied some relationship to ConfigRoot. But since ConfigRoot is now gone, toObject() can have the nicer name root().
This commit is contained in:
parent
7420a3da33
commit
1d62477338
@ -11,7 +11,7 @@ import java.util.List;
|
||||
* <p>
|
||||
* Contrast with {@link ConfigObject} which is a map from config <em>keys</em>,
|
||||
* rather than paths, to config values. A {@code Config} contains a tree of
|
||||
* {@code ConfigObject}, and {@link Config#toObject()} returns the tree's root
|
||||
* {@code ConfigObject}, and {@link Config#root()} returns the tree's root
|
||||
* object.
|
||||
*
|
||||
* <p>
|
||||
@ -55,7 +55,7 @@ import java.util.List;
|
||||
*
|
||||
* <p>
|
||||
* If you want to iterate over the contents of a {@code Config}, you have to get
|
||||
* its {@code ConfigObject} with {@link #toObject()}, and then iterate over the
|
||||
* its {@code ConfigObject} with {@link #root()}, and then iterate over the
|
||||
* {@code ConfigObject}.
|
||||
*
|
||||
*
|
||||
@ -74,7 +74,7 @@ public interface Config extends ConfigMergeable {
|
||||
*
|
||||
* @return the root object in the configuration
|
||||
*/
|
||||
ConfigObject toObject();
|
||||
ConfigObject root();
|
||||
|
||||
/**
|
||||
* Gets the origin of the {@code Config}, which may be a file, or a file
|
||||
|
@ -20,7 +20,7 @@ public interface ConfigMergeable {
|
||||
/**
|
||||
* Converts this instance to a {@link ConfigValue}. If called on a
|
||||
* {@code ConfigValue} it returns {@code this}, if called on a
|
||||
* {@link Config} it's equivalent to {@link Config#toObject}.
|
||||
* {@link Config} it's equivalent to {@link Config#root()}.
|
||||
*
|
||||
* @return this instance as a {@code ConfigValue}
|
||||
*/
|
||||
|
@ -34,7 +34,7 @@ class SimpleConfig implements Config {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractConfigObject toObject() {
|
||||
public AbstractConfigObject root() {
|
||||
return object;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class ApiExamples {
|
||||
|
||||
// a Config has an associated tree of values, with a ConfigObject
|
||||
// at the root. The ConfigObject implements java.util.Map
|
||||
val obj: ConfigObject = conf.toObject
|
||||
val obj: ConfigObject = conf.root
|
||||
|
||||
// this is how you do conf.getInt "manually" on the value tree, if you
|
||||
// were so inclined. (This is not a good approach vs. conf.getInt() above,
|
||||
|
@ -162,7 +162,7 @@ class ConfParserTest extends TestUtils {
|
||||
def duplicateKeyLastWins() {
|
||||
val obj = parseConfig("""{ "a" : 10, "a" : 11 } """)
|
||||
|
||||
assertEquals(1, obj.toObject.size())
|
||||
assertEquals(1, obj.root.size())
|
||||
assertEquals(11, obj.getInt("a"))
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ class ConfParserTest extends TestUtils {
|
||||
def duplicateKeyObjectsMerged() {
|
||||
val obj = parseConfig("""{ "a" : { "x" : 1, "y" : 2 }, "a" : { "x" : 42, "z" : 100 } }""")
|
||||
|
||||
assertEquals(1, obj.toObject.size())
|
||||
assertEquals(1, obj.root.size())
|
||||
assertEquals(3, obj.getObject("a").size())
|
||||
assertEquals(42, obj.getInt("a.x"))
|
||||
assertEquals(2, obj.getInt("a.y"))
|
||||
@ -181,7 +181,7 @@ class ConfParserTest extends TestUtils {
|
||||
def duplicateKeyObjectsMergedRecursively() {
|
||||
val obj = parseConfig("""{ "a" : { "b" : { "x" : 1, "y" : 2 } }, "a" : { "b" : { "x" : 42, "z" : 100 } } }""")
|
||||
|
||||
assertEquals(1, obj.toObject.size())
|
||||
assertEquals(1, obj.root.size())
|
||||
assertEquals(1, obj.getObject("a").size())
|
||||
assertEquals(3, obj.getObject("a.b").size())
|
||||
assertEquals(42, obj.getInt("a.b.x"))
|
||||
@ -193,7 +193,7 @@ class ConfParserTest extends TestUtils {
|
||||
def duplicateKeyObjectsMergedRecursivelyDeeper() {
|
||||
val obj = parseConfig("""{ "a" : { "b" : { "c" : { "x" : 1, "y" : 2 } } }, "a" : { "b" : { "c" : { "x" : 42, "z" : 100 } } } }""")
|
||||
|
||||
assertEquals(1, obj.toObject.size())
|
||||
assertEquals(1, obj.root.size())
|
||||
assertEquals(1, obj.getObject("a").size())
|
||||
assertEquals(1, obj.getObject("a.b").size())
|
||||
assertEquals(3, obj.getObject("a.b.c").size())
|
||||
@ -206,7 +206,7 @@ class ConfParserTest extends TestUtils {
|
||||
def duplicateKeyObjectNullObject() {
|
||||
// null is supposed to "reset" the object at key "a"
|
||||
val obj = parseConfig("""{ a : { b : 1 }, a : null, a : { c : 2 } }""")
|
||||
assertEquals(1, obj.toObject.size())
|
||||
assertEquals(1, obj.root.size())
|
||||
assertEquals(1, obj.getObject("a").size())
|
||||
assertEquals(2, obj.getInt("a.c"))
|
||||
}
|
||||
@ -214,7 +214,7 @@ class ConfParserTest extends TestUtils {
|
||||
@Test
|
||||
def duplicateKeyObjectNumberObject() {
|
||||
val obj = parseConfig("""{ a : { b : 1 }, a : 42, a : { c : 2 } }""")
|
||||
assertEquals(1, obj.toObject.size())
|
||||
assertEquals(1, obj.root.size())
|
||||
assertEquals(1, obj.getObject("a").size())
|
||||
assertEquals(2, obj.getInt("a.c"))
|
||||
}
|
||||
@ -271,7 +271,7 @@ class ConfParserTest extends TestUtils {
|
||||
for (v <- valids; change <- changes) {
|
||||
tested += 1;
|
||||
val obj = parseConfig(change(v))
|
||||
assertEquals(3, obj.toObject.size())
|
||||
assertEquals(3, obj.root.size())
|
||||
assertEquals("y", obj.getString("a"))
|
||||
assertEquals("z", obj.getString("b"))
|
||||
assertEquals(Seq(1, 2, 3), obj.getIntList("c").asScala)
|
||||
|
@ -285,13 +285,13 @@ class ConfigSubstitutionTest extends TestUtils {
|
||||
val resolved = resolve(substEnvVarObject)
|
||||
|
||||
var existed = 0
|
||||
for (k <- resolved.toObject.keySet().asScala) {
|
||||
for (k <- resolved.root.keySet().asScala) {
|
||||
val e = System.getenv(k.toUpperCase());
|
||||
if (e != null) {
|
||||
existed += 1
|
||||
assertEquals(e, resolved.getString(k))
|
||||
} else {
|
||||
assertEquals(nullValue, resolved.toObject.get(k))
|
||||
assertEquals(nullValue, resolved.root.get(k))
|
||||
}
|
||||
}
|
||||
if (existed == 0) {
|
||||
@ -315,9 +315,9 @@ class ConfigSubstitutionTest extends TestUtils {
|
||||
|
||||
val resolved = resolve(substEnvVarObject.withFallback(nulls))
|
||||
|
||||
for (k <- resolved.toObject.keySet().asScala) {
|
||||
assertNotNull(resolved.toObject.get(k))
|
||||
assertEquals(nullValue, resolved.toObject.get(k))
|
||||
for (k <- resolved.root.keySet().asScala) {
|
||||
assertNotNull(resolved.root.get(k))
|
||||
assertEquals(nullValue, resolved.root.get(k))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ class ConfigTest extends TestUtils {
|
||||
}
|
||||
|
||||
private def resolveNoSystem(v: SimpleConfig, root: SimpleConfig) = {
|
||||
SubstitutionResolver.resolve(v.toObject, root.toObject,
|
||||
SubstitutionResolver.resolve(v.root, root.root,
|
||||
ConfigResolveOptions.noSystem()).asInstanceOf[AbstractConfigObject].toConfig
|
||||
}
|
||||
|
||||
@ -95,14 +95,14 @@ class ConfigTest extends TestUtils {
|
||||
|
||||
assertEquals(1, merged.getInt("a"))
|
||||
assertEquals(2, merged.getInt("b"))
|
||||
assertEquals(2, merged.toObject.size)
|
||||
assertEquals(2, merged.root.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
def mergeEmpty() {
|
||||
val merged = merge().toConfig
|
||||
|
||||
assertEquals(0, merged.toObject.size)
|
||||
assertEquals(0, merged.root.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -111,7 +111,7 @@ class ConfigTest extends TestUtils {
|
||||
val merged = merge(obj1).toConfig
|
||||
|
||||
assertEquals(1, merged.getInt("a"))
|
||||
assertEquals(1, merged.toObject.size)
|
||||
assertEquals(1, merged.root.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -121,12 +121,12 @@ class ConfigTest extends TestUtils {
|
||||
val merged = merge(obj1, obj2).toConfig
|
||||
|
||||
assertEquals(1, merged.getInt("a"))
|
||||
assertEquals(1, merged.toObject.size)
|
||||
assertEquals(1, merged.root.size)
|
||||
|
||||
val merged2 = merge(obj2, obj1).toConfig
|
||||
|
||||
assertEquals(2, merged2.getInt("a"))
|
||||
assertEquals(1, merged2.toObject.size)
|
||||
assertEquals(1, merged2.root.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -141,7 +141,7 @@ class ConfigTest extends TestUtils {
|
||||
assertEquals(2, merged.getInt("b"))
|
||||
assertEquals(3, merged.getInt("c"))
|
||||
assertEquals(4, merged.getInt("d"))
|
||||
assertEquals(4, merged.toObject.size)
|
||||
assertEquals(4, merged.root.size)
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,12 +153,12 @@ class ConfigTest extends TestUtils {
|
||||
val obj4 = parseObject("""{ "a" : 4 }""")
|
||||
associativeMerge(Seq(obj1, obj2, obj3, obj4)) { merged =>
|
||||
assertEquals(1, merged.getInt("a"))
|
||||
assertEquals(1, merged.toObject.size)
|
||||
assertEquals(1, merged.root.size)
|
||||
}
|
||||
|
||||
associativeMerge(Seq(obj4, obj3, obj2, obj1)) { merged2 =>
|
||||
assertEquals(4, merged2.getInt("a"))
|
||||
assertEquals(1, merged2.toObject.size)
|
||||
assertEquals(1, merged2.root.size)
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,8 +171,8 @@ class ConfigTest extends TestUtils {
|
||||
assertEquals(1, merged.getInt("root.a"))
|
||||
assertEquals(2, merged.getInt("root.b"))
|
||||
assertEquals(101, merged.getInt("root.z"))
|
||||
assertEquals(1, merged.toObject.size)
|
||||
assertEquals(3, merged.getConfig("root").toObject.size)
|
||||
assertEquals(1, merged.root.size)
|
||||
assertEquals(3, merged.getConfig("root").root.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -182,12 +182,12 @@ class ConfigTest extends TestUtils {
|
||||
val merged = merge(obj1, obj2).toConfig
|
||||
|
||||
assertEquals(1, merged.getInt("a"))
|
||||
assertEquals(1, merged.toObject.size)
|
||||
assertEquals(1, merged.root.size)
|
||||
|
||||
val merged2 = merge(obj2, obj1).toConfig
|
||||
|
||||
assertEquals(1, merged2.getInt("a"))
|
||||
assertEquals(1, merged2.toObject.size)
|
||||
assertEquals(1, merged2.root.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -197,13 +197,13 @@ class ConfigTest extends TestUtils {
|
||||
val merged = merge(obj1, obj2).toConfig
|
||||
|
||||
assertEquals(1, merged.getInt("a"))
|
||||
assertEquals(1, merged.toObject.size)
|
||||
assertEquals(1, merged.root.size)
|
||||
|
||||
val merged2 = merge(obj2, obj1).toConfig
|
||||
|
||||
assertEquals(42, merged2.getConfig("a").getInt("b"))
|
||||
assertEquals(42, merged2.getInt("a.b"))
|
||||
assertEquals(1, merged2.toObject.size)
|
||||
assertEquals(1, merged2.root.size)
|
||||
assertEquals(1, merged2.getObject("a").size)
|
||||
}
|
||||
|
||||
@ -214,13 +214,13 @@ class ConfigTest extends TestUtils {
|
||||
val merged = merge(obj1, obj2).toConfig
|
||||
|
||||
assertEquals(1, merged.getInt("a"))
|
||||
assertEquals(2, merged.toObject.size)
|
||||
assertEquals(2, merged.root.size)
|
||||
|
||||
val merged2 = merge(obj2, obj1).toConfig
|
||||
|
||||
assertEquals(42, merged2.getConfig("a").getInt("b"))
|
||||
assertEquals(42, merged2.getInt("a.b"))
|
||||
assertEquals(2, merged2.toObject.size)
|
||||
assertEquals(2, merged2.root.size)
|
||||
assertEquals(1, merged2.getObject("a").size)
|
||||
}
|
||||
|
||||
@ -235,14 +235,14 @@ class ConfigTest extends TestUtils {
|
||||
|
||||
associativeMerge(Seq(obj1, obj2, obj3)) { merged =>
|
||||
assertEquals(42, merged.getInt("a.b"))
|
||||
assertEquals(1, merged.toObject.size)
|
||||
assertEquals(1, merged.root.size)
|
||||
assertEquals(1, merged.getObject("a").size())
|
||||
}
|
||||
|
||||
associativeMerge(Seq(obj3, obj2, obj1)) { merged2 =>
|
||||
assertEquals(43, merged2.getInt("a.b"))
|
||||
assertEquals(44, merged2.getInt("a.c"))
|
||||
assertEquals(1, merged2.toObject.size)
|
||||
assertEquals(1, merged2.root.size)
|
||||
assertEquals(2, merged2.getObject("a").size())
|
||||
}
|
||||
}
|
||||
@ -259,7 +259,7 @@ class ConfigTest extends TestUtils {
|
||||
associativeMerge(Seq(obj1, obj2, obj3)) { unresolved =>
|
||||
val merged = resolveNoSystem(unresolved, unresolved)
|
||||
assertEquals(42, merged.getInt("a.b"))
|
||||
assertEquals(4, merged.toObject.size)
|
||||
assertEquals(4, merged.root.size)
|
||||
assertEquals(1, merged.getObject("a").size())
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ class ConfigTest extends TestUtils {
|
||||
val merged2 = resolveNoSystem(unresolved, unresolved)
|
||||
assertEquals(43, merged2.getInt("a.b"))
|
||||
assertEquals(44, merged2.getInt("a.c"))
|
||||
assertEquals(4, merged2.toObject.size)
|
||||
assertEquals(4, merged2.root.size)
|
||||
assertEquals(2, merged2.getObject("a").size())
|
||||
}
|
||||
}
|
||||
@ -281,7 +281,7 @@ class ConfigTest extends TestUtils {
|
||||
|
||||
associativeMerge(Seq(obj1, obj2, obj3)) { merged =>
|
||||
assertEquals(1, merged.getInt("a"))
|
||||
assertEquals(1, merged.toObject.size)
|
||||
assertEquals(1, merged.root.size)
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,7 +296,7 @@ class ConfigTest extends TestUtils {
|
||||
val resolved = resolveNoSystem(merged, merged)
|
||||
|
||||
assertEquals(1, resolved.getInt("a"))
|
||||
assertEquals(3, resolved.toObject.size)
|
||||
assertEquals(3, resolved.root.size)
|
||||
}
|
||||
}
|
||||
|
||||
@ -401,7 +401,7 @@ class ConfigTest extends TestUtils {
|
||||
associativeMerge(Seq(obj1, obj2, obj3)) { merged =>
|
||||
val resolved = resolveNoSystem(merged, merged)
|
||||
|
||||
assertEquals(3, resolved.toObject.size())
|
||||
assertEquals(3, resolved.root.size())
|
||||
assertEquals(42, resolved.getInt("j"));
|
||||
assertEquals(2, resolved.getInt("b.y"))
|
||||
assertEquals(3, resolved.getInt("c.z"))
|
||||
@ -449,7 +449,7 @@ class ConfigTest extends TestUtils {
|
||||
case v: AbstractConfigValue =>
|
||||
v.ignoresFallbacks()
|
||||
case c: SimpleConfig =>
|
||||
c.toObject.ignoresFallbacks()
|
||||
c.root.ignoresFallbacks()
|
||||
}
|
||||
}
|
||||
|
||||
@ -534,7 +534,7 @@ class ConfigTest extends TestUtils {
|
||||
// to get null we have to use the get() method from Map,
|
||||
// which takes a key and not a path
|
||||
assertEquals(nullValue(), conf.getObject("nulls").get("null"))
|
||||
assertNull(conf.toObject.get("notinthefile"))
|
||||
assertNull(conf.root.get("notinthefile"))
|
||||
|
||||
// get stuff with getValue
|
||||
assertEquals(intValue(42), conf.getValue("ints.fortyTwo"))
|
||||
|
@ -398,12 +398,12 @@ class ConfigValueTest extends TestUtils {
|
||||
assertTrue(obj.hasPath("b"))
|
||||
|
||||
// hasPath() is false for null values but containsKey is true
|
||||
assertEquals(nullValue(), obj.toObject.get("a"))
|
||||
assertTrue(obj.toObject.containsKey("a"))
|
||||
assertEquals(nullValue(), obj.root.get("a"))
|
||||
assertTrue(obj.root.containsKey("a"))
|
||||
assertFalse(obj.hasPath("a"))
|
||||
|
||||
// false for totally absent values
|
||||
assertFalse(obj.toObject.containsKey("notinhere"))
|
||||
assertFalse(obj.root.containsKey("notinhere"))
|
||||
assertFalse(obj.hasPath("notinhere"))
|
||||
|
||||
// throws proper exceptions
|
||||
|
@ -45,12 +45,12 @@ class EquivalentsTest extends TestUtils {
|
||||
|
||||
private def parse(flavor: ConfigSyntax, f: File) = {
|
||||
val options = ConfigParseOptions.defaults().setSyntax(flavor)
|
||||
postParse(ConfigFactory.parseFile(f, options).toObject)
|
||||
postParse(ConfigFactory.parseFile(f, options).root)
|
||||
}
|
||||
|
||||
private def parse(f: File) = {
|
||||
val options = ConfigParseOptions.defaults()
|
||||
postParse(ConfigFactory.parseFile(f, options).toObject)
|
||||
postParse(ConfigFactory.parseFile(f, options).root)
|
||||
}
|
||||
|
||||
// would like each "equivNN" directory to be a suite and each file in the dir
|
||||
|
@ -88,7 +88,7 @@ class PropertiesTest extends TestUtils {
|
||||
|
||||
val conf = ConfigFactory.parseProperties(props, ConfigParseOptions.defaults())
|
||||
|
||||
assertEquals(2, conf.toObject.size())
|
||||
assertEquals(2, conf.root.size())
|
||||
assertEquals("foo", conf.getString("a.b"))
|
||||
assertEquals("foo", conf.getString("x.y.z"))
|
||||
}
|
||||
|
@ -171,18 +171,18 @@ class PublicApiTest extends TestUtils {
|
||||
@Test
|
||||
def roundTripUnwrap() {
|
||||
val conf = ConfigFactory.load("test01")
|
||||
assertTrue(conf.toObject.size > 4) // "has a lot of stuff in it"
|
||||
val unwrapped = conf.toObject.unwrapped()
|
||||
assertTrue(conf.root.size > 4) // "has a lot of stuff in it"
|
||||
val unwrapped = conf.root.unwrapped()
|
||||
val rewrapped = ConfigValueFactory.fromMap(unwrapped, conf.origin().description())
|
||||
val reunwrapped = rewrapped.unwrapped()
|
||||
assertEquals(conf.toObject, rewrapped)
|
||||
assertEquals(conf.root, rewrapped)
|
||||
assertEquals(reunwrapped, unwrapped)
|
||||
}
|
||||
|
||||
private def testFromPathMap(expectedValue: ConfigObject, createFrom: java.util.Map[String, Object]) {
|
||||
assertEquals(expectedValue, ConfigFactory.parseMap(createFrom).toObject)
|
||||
assertEquals(expectedValue, ConfigFactory.parseMap(createFrom).root)
|
||||
assertEquals(defaultValueDesc, ConfigFactory.parseMap(createFrom).origin().description())
|
||||
assertEquals(expectedValue, ConfigFactory.parseMap(createFrom, "foo").toObject)
|
||||
assertEquals(expectedValue, ConfigFactory.parseMap(createFrom, "foo").root)
|
||||
assertEquals("foo", ConfigFactory.parseMap(createFrom, "foo").origin().description())
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ class PublicApiTest extends TestUtils {
|
||||
|
||||
val conf = ConfigFactory.parseMap(pathMapValue)
|
||||
|
||||
assertEquals(2, conf.toObject.size)
|
||||
assertEquals(2, conf.root.size)
|
||||
assertEquals(4, conf.getInt("b.x.y"))
|
||||
assertEquals(5, conf.getInt("b.z"))
|
||||
assertEquals(1, conf.getInt("a.c"))
|
||||
|
@ -336,7 +336,7 @@ abstract trait TestUtils {
|
||||
protected def doubleValue(d: Double) = new ConfigDouble(fakeOrigin(), d, null)
|
||||
|
||||
protected def parseObject(s: String) = {
|
||||
parseConfig(s).toObject
|
||||
parseConfig(s).root
|
||||
}
|
||||
|
||||
protected def parseConfig(s: String) = {
|
||||
|
Loading…
Reference in New Issue
Block a user