mirror of
https://github.com/lightbend/config.git
synced 2025-03-18 13:20:23 +08:00
Move ConfigMergeable.toValue to be private, as MergeableValue.toFallbackValue
Avoids confusion because ConfigValue.toValue was pointless and Config.toValue was not as clear as Config.root (plus having two ways to do it on Config was strange). This change does require a cast in the withFallback implementation but we already have the analogous pattern all over the place (i.e. assuming that instances of the public interfaces are always instances of our private implementations).
This commit is contained in:
parent
b50ed75f92
commit
baa126633a
@ -87,9 +87,6 @@ public interface Config extends ConfigMergeable {
|
||||
@Override
|
||||
Config withFallback(ConfigMergeable other);
|
||||
|
||||
@Override
|
||||
ConfigObject toValue();
|
||||
|
||||
/**
|
||||
* Returns a replacement config with all substitutions (the
|
||||
* <code>${foo.bar}</code> syntax, see <a
|
||||
|
@ -17,15 +17,6 @@ package com.typesafe.config;
|
||||
* implementations will break.
|
||||
*/
|
||||
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#root()}.
|
||||
*
|
||||
* @return this instance as a {@code ConfigValue}
|
||||
*/
|
||||
ConfigValue toValue();
|
||||
|
||||
/**
|
||||
* Returns a new value computed by merging this value with another, with
|
||||
* keys in this value "winning" over the other one. Only
|
||||
|
@ -35,6 +35,11 @@ abstract class AbstractConfigObject extends AbstractConfigValue implements
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractConfigObject toFallbackValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This looks up the key with no transformation or type conversion of any
|
||||
* kind, and returns null if the key is not present.
|
||||
|
@ -16,7 +16,7 @@ import com.typesafe.config.ConfigValue;
|
||||
* improperly-factored and non-modular code. Please don't add parent().
|
||||
*
|
||||
*/
|
||||
abstract class AbstractConfigValue implements ConfigValue {
|
||||
abstract class AbstractConfigValue implements ConfigValue, MergeableValue {
|
||||
|
||||
final private ConfigOrigin origin;
|
||||
|
||||
@ -72,7 +72,7 @@ abstract class AbstractConfigValue implements ConfigValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractConfigValue toValue() {
|
||||
public AbstractConfigValue toFallbackValue() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ abstract class AbstractConfigValue implements ConfigValue {
|
||||
if (ignoresFallbacks()) {
|
||||
return this;
|
||||
} else {
|
||||
ConfigValue other = mergeable.toValue();
|
||||
ConfigValue other = ((MergeableValue) mergeable).toFallbackValue();
|
||||
|
||||
if (other instanceof Unmergeable) {
|
||||
return mergedWithTheUnmergeable((Unmergeable) other);
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.typesafe.config.impl;
|
||||
|
||||
import com.typesafe.config.ConfigMergeable;
|
||||
import com.typesafe.config.ConfigValue;
|
||||
|
||||
interface MergeableValue extends ConfigMergeable {
|
||||
// converts a Config to its root object and a ConfigValue to itself
|
||||
ConfigValue toFallbackValue();
|
||||
}
|
@ -27,7 +27,7 @@ import com.typesafe.config.ConfigValueType;
|
||||
* key-value pairs would be all the tree's leaf values, in a big flat list with
|
||||
* their full paths.
|
||||
*/
|
||||
final class SimpleConfig implements Config {
|
||||
final class SimpleConfig implements Config, MergeableValue {
|
||||
|
||||
final private AbstractConfigObject object;
|
||||
|
||||
@ -378,7 +378,7 @@ final class SimpleConfig implements Config {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractConfigObject toValue() {
|
||||
public AbstractConfigObject toFallbackValue() {
|
||||
return object;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user