@Test public void testOriginalsWithPrefix() { Properties props = new Properties(); props.put("foo.bar", "abc"); props.put("setting", "def"); TestConfig config = new TestConfig(props); Map<String, Object> originalsWithPrefix = config.originalsWithPrefix("foo."); assertTrue(config.unused().contains("foo.bar")); originalsWithPrefix.get("bar"); assertFalse(config.unused().contains("foo.bar")); Map<String, Object> expected = new HashMap<>(); expected.put("bar", "abc"); assertEquals(expected, originalsWithPrefix); }
public Map<String, Object> originalsWithPrefix(String prefix) { Map<String, Object> result = new RecordingMap<>(prefix, false); for (Map.Entry<String, ?> entry : originals.entrySet()) { if (entry.getKey().startsWith(prefix) && entry.getKey().length() > prefix.length()) result.put(entry.getKey().substring(prefix.length()), entry.getValue()); } return result; }
AbstractConfig { public Map<String, Object> originalsWithPrefix(String prefix) { Map<String, Object> result = new RecordingMap<>(prefix, false); for (Map.Entry<String, ?> entry : originals.entrySet()) { if (entry.getKey().startsWith(prefix) && entry.getKey().length() > prefix.length()) result.put(entry.getKey().substring(prefix.length()), entry.getValue()); } return result; } }
AbstractConfig { public Map<String, Object> originalsWithPrefix(String prefix) { Map<String, Object> result = new RecordingMap<>(prefix, false); for (Map.Entry<String, ?> entry : originals.entrySet()) { if (entry.getKey().startsWith(prefix) && entry.getKey().length() > prefix.length()) result.put(entry.getKey().substring(prefix.length()), entry.getValue()); } return result; } @SuppressWarnings("unchecked")  AbstractConfig(ConfigDef definition, Map<?, ?> originals, boolean doLog);  AbstractConfig(ConfigDef definition, Map<?, ?> originals); }
AbstractConfig { public Map<String, Object> originalsWithPrefix(String prefix) { Map<String, Object> result = new RecordingMap<>(prefix, false); for (Map.Entry<String, ?> entry : originals.entrySet()) { if (entry.getKey().startsWith(prefix) && entry.getKey().length() > prefix.length()) result.put(entry.getKey().substring(prefix.length()), entry.getValue()); } return result; } @SuppressWarnings("unchecked")  AbstractConfig(ConfigDef definition, Map<?, ?> originals, boolean doLog);  AbstractConfig(ConfigDef definition, Map<?, ?> originals); void ignore(String key); Short getShort(String key); Integer getInt(String key); Long getLong(String key); Double getDouble(String key); @SuppressWarnings("unchecked") List<String> getList(String key); Boolean getBoolean(String key); String getString(String key); ConfigDef.Type typeOf(String key); Password getPassword(String key); Class<?> getClass(String key); Set<String> unused(); Map<String, Object> originals(); Map<String, String> originalsStrings(); Map<String, Object> originalsWithPrefix(String prefix); Map<String, Object> valuesWithPrefixOverride(String prefix); Map<String, ?> values(); void logUnused(); T getConfiguredInstance(String key, Class<T> t); List<T> getConfiguredInstances(String key, Class<T> t); List<T> getConfiguredInstances(String key, Class<T> t, Map<String, Object> configOverrides); @Override boolean equals(Object o); @Override int hashCode(); }
AbstractConfig { public Map<String, Object> originalsWithPrefix(String prefix) { Map<String, Object> result = new RecordingMap<>(prefix, false); for (Map.Entry<String, ?> entry : originals.entrySet()) { if (entry.getKey().startsWith(prefix) && entry.getKey().length() > prefix.length()) result.put(entry.getKey().substring(prefix.length()), entry.getValue()); } return result; } @SuppressWarnings("unchecked")  AbstractConfig(ConfigDef definition, Map<?, ?> originals, boolean doLog);  AbstractConfig(ConfigDef definition, Map<?, ?> originals); void ignore(String key); Short getShort(String key); Integer getInt(String key); Long getLong(String key); Double getDouble(String key); @SuppressWarnings("unchecked") List<String> getList(String key); Boolean getBoolean(String key); String getString(String key); ConfigDef.Type typeOf(String key); Password getPassword(String key); Class<?> getClass(String key); Set<String> unused(); Map<String, Object> originals(); Map<String, String> originalsStrings(); Map<String, Object> originalsWithPrefix(String prefix); Map<String, Object> valuesWithPrefixOverride(String prefix); Map<String, ?> values(); void logUnused(); T getConfiguredInstance(String key, Class<T> t); List<T> getConfiguredInstances(String key, Class<T> t); List<T> getConfiguredInstances(String key, Class<T> t, Map<String, Object> configOverrides); @Override boolean equals(Object o); @Override int hashCode();  }