Java 类org.apache.commons.configuration.tree.OverrideCombiner 实例源码

项目:java-dynamicconfig    文件:ConcurrentConfigurationTest.java   
@Test
public void modifyConfigurationTest() {
    CombinedConfiguration allConfig = new CombinedConfiguration(new OverrideCombiner());
    HierarchicalConfiguration confA = new HierarchicalConfiguration();
    HierarchicalConfiguration confB = new HierarchicalConfiguration();

    confA.setProperty("a.a", 1);
    confB.setProperty("a.a", 2);

    allConfig.addConfiguration(confA, "a");
    allConfig.addConfiguration(confB, "b");
    allConfig.addConfiguration(confB, "d", "b.b");
    allConfig.addConfiguration(confB, "c", "c.c");

    System.out.println(allConfig.getInt("a.a"));
    System.out.println(allConfig.getInt("b.b.a.a"));
    System.out.println(allConfig.getInt("c.c.a.a"));

    ConcurrentConfiguration concurrentConfiguration = new ConcurrentConfiguration(allConfig);

    System.out.println(concurrentConfiguration.getInt("a.a"));

    concurrentConfiguration.withConfiguration(cc -> {
        cc.clear();
        cc.addConfiguration(confB, "b");
        cc.addConfiguration(confA, "a");
    });

    System.out.println(concurrentConfiguration.getInt("a.a"));

}