DynamicPropertyUpdater { public void updateProperties(final WatchedUpdateResult result, final Configuration config, final boolean ignoreDeletesFromSource) { if (result == null || !result.hasChanges()) { return; } logger.debug("incremental result? [{}]", result.isIncremental()); logger.debug("ignored deletes from source? [{}]", ignoreDeletesFromSource); if (!result.isIncremental()) { Map<String, Object> props = result.getComplete(); if (props == null) { return; } for (Entry<String, Object> entry : props.entrySet()) { addOrChangeProperty(entry.getKey(), entry.getValue(), config); } Set<String> existingKeys = new HashSet<String>(); for (Iterator<String> i = config.getKeys(); i.hasNext();) { existingKeys.add(i.next()); } if (!ignoreDeletesFromSource) { for (String key : existingKeys) { if (!props.containsKey(key)) { deleteProperty(key, config); } } } } else { Map<String, Object> props = result.getAdded(); if (props != null) { for (Entry<String, Object> entry : props.entrySet()) { addOrChangeProperty(entry.getKey(), entry.getValue(), config); } } props = result.getChanged(); if (props != null) { for (Entry<String, Object> entry : props.entrySet()) { addOrChangeProperty(entry.getKey(), entry.getValue(), config); } } if (!ignoreDeletesFromSource) { props = result.getDeleted(); if (props != null) { for (String name : props.keySet()) { deleteProperty(name, config); } } } } }  void updateProperties(final WatchedUpdateResult result, final Configuration config,
            final boolean ignoreDeletesFromSource);  }
@Test public void testUpdateProperties() throws InterruptedException { AbstractConfiguration.setDefaultListDelimiter(','); AbstractConfiguration config = new ConcurrentCompositeConfiguration(); config.addConfigurationListener(new ExpandedConfigurationListenerAdapter(new MyListener())); MyListener.resetCount(); config.setProperty("test", "host,host1,host2"); config.setProperty("test12", "host12"); Map<String,Object> added = Maps.newHashMap(); added.put("test.host","test,test1"); Map<String,Object> changed = Maps.newHashMap(); changed.put("test","host,host1"); changed.put("test.host",""); dynamicPropertyUpdater.updateProperties(WatchedUpdateResult.createIncremental(added, changed, null), config, false); assertEquals("",config.getProperty("test.host")); assertEquals(2,((CopyOnWriteArrayList)(config.getProperty("test"))).size()); assertTrue(((CopyOnWriteArrayList)(config.getProperty("test"))).contains("host")); assertTrue(((CopyOnWriteArrayList)(config.getProperty("test"))).contains("host1")); assertEquals(5, MyListener.count); }