@Test public void testAddorChangeProperty(){ AbstractConfiguration.setDefaultListDelimiter(','); AbstractConfiguration config = new ConcurrentCompositeConfiguration(); config.addConfigurationListener(new ExpandedConfigurationListenerAdapter(new MyListener())); MyListener.resetCount(); config.setProperty("test.host", "test,test1,test2"); assertEquals(1, MyListener.count); dynamicPropertyUpdater.addOrChangeProperty("test.host", "test,test1,test2", config); assertEquals(3,((CopyOnWriteArrayList)(config.getProperty("test.host"))).size()); assertTrue(((CopyOnWriteArrayList)(config.getProperty("test.host"))).contains("test")); assertTrue(((CopyOnWriteArrayList)(config.getProperty("test.host"))).contains("test1")); assertTrue(((CopyOnWriteArrayList)(config.getProperty("test.host"))).contains("test2")); assertEquals(1, MyListener.count); dynamicPropertyUpdater.addOrChangeProperty("test.host", "test,test1,test2", config); assertEquals(3,((CopyOnWriteArrayList)(config.getProperty("test.host"))).size()); assertTrue(((CopyOnWriteArrayList)(config.getProperty("test.host"))).contains("test")); assertTrue(((CopyOnWriteArrayList)(config.getProperty("test.host"))).contains("test1")); assertTrue(((CopyOnWriteArrayList)(config.getProperty("test.host"))).contains("test2")); assertEquals(1, MyListener.count); dynamicPropertyUpdater.addOrChangeProperty("test.host", "test,test1", config); assertEquals(2,((CopyOnWriteArrayList)(config.getProperty("test.host"))).size()); assertTrue(((CopyOnWriteArrayList)(config.getProperty("test.host"))).contains("test")); assertTrue(((CopyOnWriteArrayList)(config.getProperty("test.host"))).contains("test1")); assertEquals(2, MyListener.count); dynamicPropertyUpdater.addOrChangeProperty("test.host1", "test1,test12", config); assertEquals(2,((CopyOnWriteArrayList)(config.getProperty("test.host1"))).size()); assertTrue(((CopyOnWriteArrayList)(config.getProperty("test.host1"))).contains("test1")); assertTrue(((CopyOnWriteArrayList)(config.getProperty("test.host1"))).contains("test12")); assertEquals(3, MyListener.count); config.setProperty("test.host1", "test1.test12"); dynamicPropertyUpdater.addOrChangeProperty("test.host1", "test1.test12", config); assertEquals("test1.test12",config.getProperty("test.host1")); assertEquals(4, MyListener.count); }
void addOrChangeProperty(final String name, final Object newValue, final Configuration config) { try { if (!config.containsKey(name)) { logger.debug("adding property key [{}], value [{}]", name, newValue); config.addProperty(name, newValue); } else { Object oldValue = config.getProperty(name); if (newValue != null) { Object newValueArray; if (oldValue instanceof CopyOnWriteArrayList && AbstractConfiguration.getDefaultListDelimiter() != '\0'){ newValueArray = new CopyOnWriteArrayList(); Iterable<String> stringiterator = Splitter.on(AbstractConfiguration.getDefaultListDelimiter()).omitEmptyStrings().trimResults().split((String)newValue); for(String s :stringiterator){ ((CopyOnWriteArrayList) newValueArray).add(s); } } else { newValueArray = newValue; } if (!newValueArray.equals(oldValue)) { logger.debug("updating property key [{}], value [{}]", name, newValue); config.setProperty(name, newValue); } } else if (oldValue != null) { logger.debug("nulling out property key [{}]", name); config.setProperty(name, null); } } } catch (ValidationException e) { logger.warn("Validation failed for property " + name, e); } }
DynamicPropertyUpdater { void addOrChangeProperty(final String name, final Object newValue, final Configuration config) { try { if (!config.containsKey(name)) { logger.debug("adding property key [{}], value [{}]", name, newValue); config.addProperty(name, newValue); } else { Object oldValue = config.getProperty(name); if (newValue != null) { Object newValueArray; if (oldValue instanceof CopyOnWriteArrayList && AbstractConfiguration.getDefaultListDelimiter() != '\0'){ newValueArray = new CopyOnWriteArrayList(); Iterable<String> stringiterator = Splitter.on(AbstractConfiguration.getDefaultListDelimiter()).omitEmptyStrings().trimResults().split((String)newValue); for(String s :stringiterator){ ((CopyOnWriteArrayList) newValueArray).add(s); } } else { newValueArray = newValue; } if (!newValueArray.equals(oldValue)) { logger.debug("updating property key [{}], value [{}]", name, newValue); config.setProperty(name, newValue); } } else if (oldValue != null) { logger.debug("nulling out property key [{}]", name); config.setProperty(name, null); } } } catch (ValidationException e) { logger.warn("Validation failed for property " + name, e); } } }
DynamicPropertyUpdater { void addOrChangeProperty(final String name, final Object newValue, final Configuration config) { try { if (!config.containsKey(name)) { logger.debug("adding property key [{}], value [{}]", name, newValue); config.addProperty(name, newValue); } else { Object oldValue = config.getProperty(name); if (newValue != null) { Object newValueArray; if (oldValue instanceof CopyOnWriteArrayList && AbstractConfiguration.getDefaultListDelimiter() != '\0'){ newValueArray = new CopyOnWriteArrayList(); Iterable<String> stringiterator = Splitter.on(AbstractConfiguration.getDefaultListDelimiter()).omitEmptyStrings().trimResults().split((String)newValue); for(String s :stringiterator){ ((CopyOnWriteArrayList) newValueArray).add(s); } } else { newValueArray = newValue; } if (!newValueArray.equals(oldValue)) { logger.debug("updating property key [{}], value [{}]", name, newValue); config.setProperty(name, newValue); } } else if (oldValue != null) { logger.debug("nulling out property key [{}]", name); config.setProperty(name, null); } } } catch (ValidationException e) { logger.warn("Validation failed for property " + name, e); } }  }
DynamicPropertyUpdater { void addOrChangeProperty(final String name, final Object newValue, final Configuration config) { try { if (!config.containsKey(name)) { logger.debug("adding property key [{}], value [{}]", name, newValue); config.addProperty(name, newValue); } else { Object oldValue = config.getProperty(name); if (newValue != null) { Object newValueArray; if (oldValue instanceof CopyOnWriteArrayList && AbstractConfiguration.getDefaultListDelimiter() != '\0'){ newValueArray = new CopyOnWriteArrayList(); Iterable<String> stringiterator = Splitter.on(AbstractConfiguration.getDefaultListDelimiter()).omitEmptyStrings().trimResults().split((String)newValue); for(String s :stringiterator){ ((CopyOnWriteArrayList) newValueArray).add(s); } } else { newValueArray = newValue; } if (!newValueArray.equals(oldValue)) { logger.debug("updating property key [{}], value [{}]", name, newValue); config.setProperty(name, newValue); } } else if (oldValue != null) { logger.debug("nulling out property key [{}]", name); config.setProperty(name, null); } } } catch (ValidationException e) { logger.warn("Validation failed for property " + name, e); } }  void updateProperties(final WatchedUpdateResult result, final Configuration config,
            final boolean ignoreDeletesFromSource); }
DynamicPropertyUpdater { void addOrChangeProperty(final String name, final Object newValue, final Configuration config) { try { if (!config.containsKey(name)) { logger.debug("adding property key [{}], value [{}]", name, newValue); config.addProperty(name, newValue); } else { Object oldValue = config.getProperty(name); if (newValue != null) { Object newValueArray; if (oldValue instanceof CopyOnWriteArrayList && AbstractConfiguration.getDefaultListDelimiter() != '\0'){ newValueArray = new CopyOnWriteArrayList(); Iterable<String> stringiterator = Splitter.on(AbstractConfiguration.getDefaultListDelimiter()).omitEmptyStrings().trimResults().split((String)newValue); for(String s :stringiterator){ ((CopyOnWriteArrayList) newValueArray).add(s); } } else { newValueArray = newValue; } if (!newValueArray.equals(oldValue)) { logger.debug("updating property key [{}], value [{}]", name, newValue); config.setProperty(name, newValue); } } else if (oldValue != null) { logger.debug("nulling out property key [{}]", name); config.setProperty(name, null); } } } catch (ValidationException e) { logger.warn("Validation failed for property " + name, e); } }  void updateProperties(final WatchedUpdateResult result, final Configuration config,
            final boolean ignoreDeletesFromSource);  }