/** * Create a new instance. * * @param config configuration * @param mpConfigSources config sources * @param converterClasses classes of converters * @param converters class to converter mapping */ MpConfig(Config config, List<ConfigSource> mpConfigSources, Set<Class<?>> converterClasses, Map<Class<?>, Converter<?>> converters) { final AtomicReference<Config> ref = new AtomicReference<>(config); config.onChange(newConfig -> { ref.set(newConfig); return true; }); this.config = ref::get; this.mpConfigSources = mpConfigSources; this.propertyNames = Stream.concat(mpConfigSources.stream() .flatMap(cs -> cs.getPropertyNames().stream()), config.traverse(Config::isLeaf) .map(Config::key) .map(Config.Key::toString)) .collect(Collectors.toSet()); this.converterClasses = new HashSet<>(converterClasses); this.converters = converters; }
public Set<String> keySet() { return delegate.getPropertyNames(); }
public boolean containsKey(final Object key) { //noinspection SuspiciousMethodCalls - it's OK in this case return delegate.getPropertyNames().contains(key); }
public boolean isEmpty() { // may be cheaper in some cases return delegate.getPropertyNames().isEmpty(); }
public boolean isEmpty() { // may be cheaper in some cases return delegate.getPropertyNames().isEmpty(); }
public boolean isEmpty() { // may be cheaper in some cases return delegate.getPropertyNames().isEmpty(); }
public int size() { return delegate.getPropertyNames().size(); }
public int size() { return delegate.getPropertyNames().size(); }
public int size() { return delegate.getPropertyNames().size(); }
private static Set<String> getPropertyNames(final Iterable<? extends ConfigSource> configSources) { final Set<String> returnValue = new HashSet<>(); if (configSources != null) { for (final ConfigSource configSource : configSources) { if (configSource != null) { final Set<String> configSourcePropertyNames = configSource.getPropertyNames(); if (configSourcePropertyNames != null && !configSourcePropertyNames.isEmpty()) { returnValue.addAll(configSourcePropertyNames); } } } } return Collections.unmodifiableSet(returnValue); }
@Override public Iterable<String> getPropertyNames() { return configSources.stream().flatMap(c -> c.getPropertyNames().stream()).collect(Collectors.toSet()); }
@Test public void testGetPropertyNames() { String configKey = "some.arbitrary.key"; String configValue = "value"; System.setProperty(configKey, configValue); AtomicBoolean foundKey = new AtomicBoolean(false); config.getConfigSources().forEach(c -> { if(c.getPropertyNames().contains(configKey)) { foundKey.set(true); } }); Assert.assertTrue(foundKey.get(), "Unable to find property "+configKey); } }
public Iterator<String> iterator() { return new Itr(delegate.getPropertyNames().iterator()); }
public Iterator<Entry<String, String>> iterator() { return new Itr(delegate.getPropertyNames().iterator()); }
/** * Create a new instance. * * @param config configuration * @param mpConfigSources config sources * @param converterClasses classes of converters * @param converters class to converter mapping */ MpConfig(Config config, List<ConfigSource> mpConfigSources, Set<Class<?>> converterClasses, Map<Class<?>, Converter<?>> converters) { final AtomicReference<Config> ref = new AtomicReference<>(config); config.onChange(newConfig -> { ref.set(newConfig); return true; }); this.config = ref::get; this.mpConfigSources = mpConfigSources; this.propertyNames = Stream.concat(mpConfigSources.stream() .flatMap(cs -> cs.getPropertyNames().stream()), config.traverse(Config::isLeaf) .map(Config::key) .map(Config.Key::toString)) .collect(Collectors.toSet()); this.converterClasses = new HashSet<>(converterClasses); this.converters = converters; }