mirror of
https://github.com/lightbend/config.git
synced 2025-03-22 23:30:27 +08:00
Simple implementation to turn a Config into a java.util.Properties
This commit is contained in:
parent
09146706db
commit
1c21ab9280
@ -6,6 +6,7 @@ package com.typesafe.config;
|
|||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@ -1061,4 +1062,11 @@ public interface Config extends ConfigMergeable {
|
|||||||
* @return the new instance with the new map entry
|
* @return the new instance with the new map entry
|
||||||
*/
|
*/
|
||||||
Config withValue(String path, ConfigValue value);
|
Config withValue(String path, ConfigValue value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a {@code java.util.Properties} object for each entry in this Config instance.
|
||||||
|
*
|
||||||
|
* @return a new Properties instance
|
||||||
|
*/
|
||||||
|
Properties toProperties();
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,8 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import com.typesafe.config.Config;
|
import com.typesafe.config.Config;
|
||||||
import com.typesafe.config.ConfigException;
|
import com.typesafe.config.ConfigException;
|
||||||
import com.typesafe.config.ConfigList;
|
import com.typesafe.config.ConfigList;
|
||||||
@ -1009,6 +1009,17 @@ final class SimpleConfig implements Config, MergeableValue, Serializable {
|
|||||||
return new SimpleConfig(root().withValue(path, v));
|
return new SimpleConfig(root().withValue(path, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Properties toProperties() {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
for(Map.Entry<String, ConfigValue> entry : entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
String value = entry.getValue().unwrapped().toString();
|
||||||
|
properties.setProperty(key, value);
|
||||||
|
}
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
SimpleConfig atKey(ConfigOrigin origin, String key) {
|
SimpleConfig atKey(ConfigOrigin origin, String key) {
|
||||||
return root().atKey(origin, key);
|
return root().atKey(origin, key);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user