@Test public void testMerge() throws Exception { List<IChangeableConfig> raw = Lists.newArrayList(); ChangeableConfig first = new ChangeableConfig("first"); first.copyOf(ImmutableMap.of("mix", "m1", "k1", "v1")); raw.add(first); ChangeableConfig second = new ChangeableConfig("second"); second.copyOf(ImmutableMap.of("mix", "m2", "k2", "v2")); raw.add(second); MergedConfig merged = new MergedConfig(raw); assertThat(merged.getName(), is("first,second")); assertThat(merged.get("mix"), is("m1")); assertThat(merged.get("k1"), is("v1")); assertThat(merged.get("k2"), is("v2")); final AtomicInteger count = new AtomicInteger(0); merged.addListener(new IChangeListener() { @Override public void changed(IConfig config) { count.incrementAndGet(); } }); assertThat(count.get(), is(1)); first.notifyListeners(); assertThat(count.get(), is(2)); second.notifyListeners(); assertThat(count.get(), is(3)); }
private void merge() { Map<String, String> m = Maps.newHashMap(); for (IChangeableConfig c : this.configs) { m.putAll(c.getAll()); } copyOf(m); notifyListeners(); }
MergedConfig extends ChangeableConfig implements IChangeableConfig { private void merge() { Map<String, String> m = Maps.newHashMap(); for (IChangeableConfig c : this.configs) { m.putAll(c.getAll()); } copyOf(m); notifyListeners(); } }
MergedConfig extends ChangeableConfig implements IChangeableConfig { private void merge() { Map<String, String> m = Maps.newHashMap(); for (IChangeableConfig c : this.configs) { m.putAll(c.getAll()); } copyOf(m); notifyListeners(); } MergedConfig(List<IChangeableConfig> configs); }
MergedConfig extends ChangeableConfig implements IChangeableConfig { private void merge() { Map<String, String> m = Maps.newHashMap(); for (IChangeableConfig c : this.configs) { m.putAll(c.getAll()); } copyOf(m); notifyListeners(); } MergedConfig(List<IChangeableConfig> configs); @Override String toString(); }
MergedConfig extends ChangeableConfig implements IChangeableConfig { private void merge() { Map<String, String> m = Maps.newHashMap(); for (IChangeableConfig c : this.configs) { m.putAll(c.getAll()); } copyOf(m); notifyListeners(); } MergedConfig(List<IChangeableConfig> configs); @Override String toString();  }