Configuration implements Iterable<Map.Entry<String,String>>,
                                      Writable { public Map<String,String> getValByRegex(String regex) { Pattern p = Pattern.compile(regex); Map<String,String> result = new HashMap<String,String>(); List<String> resultKeys = new ArrayList<>(); Matcher m; for(Map.Entry<Object,Object> item: getProps().entrySet()) { if (item.getKey() instanceof String && item.getValue() instanceof String) { m = p.matcher((String)item.getKey()); if(m.find()) { resultKeys.add((String) item.getKey()); } } } resultKeys.forEach(item -> result.put(item, substituteVars(getProps().getProperty(item)))); return result; } Configuration();  Configuration(boolean loadDefaults); @SuppressWarnings("unchecked")  Configuration(Configuration other); static void addDeprecations(DeprecationDelta[] deltas); @Deprecated static void addDeprecation(String key, String[] newKeys,
      String customMessage); static void addDeprecation(String key, String newKey,
	      String customMessage); @Deprecated static void addDeprecation(String key, String[] newKeys); static void addDeprecation(String key, String newKey); static boolean isDeprecated(String key); void setDeprecatedProperties(); static synchronized void reloadExistingConfigurations(); static synchronized void addDefaultResource(String name); static void setRestrictSystemPropertiesDefault(boolean val); void setRestrictSystemProperties(boolean val); void addResource(String name); void addResource(String name, boolean restrictedParser); void addResource(URL url); void addResource(URL url, boolean restrictedParser); void addResource(Path file); void addResource(Path file, boolean restrictedParser); void addResource(InputStream in); void addResource(InputStream in, boolean restrictedParser); void addResource(InputStream in, String name); void addResource(InputStream in, String name,
      boolean restrictedParser); void addResource(Configuration conf); synchronized void reloadConfiguration(); String get(String name); @VisibleForTesting void setAllowNullValueProperties( boolean val ); void setRestrictSystemProps(boolean val); @VisibleForTesting boolean onlyKeyExists(String name); String getTrimmed(String name); String getTrimmed(String name, String defaultValue); String getRaw(String name); void set(String name, String value); void set(String name, String value, String source); synchronized void unset(String name); synchronized void setIfUnset(String name, String value); String get(String name, String defaultValue); int getInt(String name, int defaultValue); int[] getInts(String name); void setInt(String name, int value); long getLong(String name, long defaultValue); long getLongBytes(String name, long defaultValue); void setLong(String name, long value); float getFloat(String name, float defaultValue); void setFloat(String name, float value); double getDouble(String name, double defaultValue); void setDouble(String name, double value); boolean getBoolean(String name, boolean defaultValue); void setBoolean(String name, boolean value); void setBooleanIfUnset(String name, boolean value); void setEnum(String name, T value); T getEnum(String name, T defaultValue); void setTimeDuration(String name, long value, TimeUnit unit); long getTimeDuration(String name, long defaultValue, TimeUnit unit); long getTimeDuration(String name, String defaultValue, TimeUnit unit); long getTimeDuration(String name, long defaultValue,
      TimeUnit defaultUnit, TimeUnit returnUnit); long getTimeDuration(String name, String defaultValue,
      TimeUnit defaultUnit, TimeUnit returnUnit); long getTimeDurationHelper(String name, String vStr, TimeUnit unit); long[] getTimeDurations(String name, TimeUnit unit); double getStorageSize(String name, String defaultValue,
      StorageUnit targetUnit); double getStorageSize(String name, double defaultValue,
      StorageUnit targetUnit); void setStorageSize(String name, double value, StorageUnit unit); Pattern getPattern(String name, Pattern defaultValue); void setPattern(String name, Pattern pattern); @InterfaceStability.Unstable synchronized String[] getPropertySources(String name); IntegerRanges getRange(String name, String defaultValue); Collection<String> getStringCollection(String name); String[] getStrings(String name); String[] getStrings(String name, String... defaultValue); Collection<String> getTrimmedStringCollection(String name); String[] getTrimmedStrings(String name); String[] getTrimmedStrings(String name, String... defaultValue); void setStrings(String name, String... values); char[] getPassword(String name); char[] getPasswordFromCredentialProviders(String name); InetSocketAddress getSocketAddr(
      String hostProperty,
      String addressProperty,
      String defaultAddressValue,
      int defaultPort); InetSocketAddress getSocketAddr(
      String name, String defaultAddress, int defaultPort); void setSocketAddr(String name, InetSocketAddress addr); InetSocketAddress updateConnectAddr(
      String hostProperty,
      String addressProperty,
      String defaultAddressValue,
      InetSocketAddress addr); InetSocketAddress updateConnectAddr(String name,
                                             InetSocketAddress addr); Class<?> getClassByName(String name); Class<?> getClassByNameOrNull(String name); Class<?>[] getClasses(String name, Class<?> ... defaultValue); Class<?> getClass(String name, Class<?> defaultValue); Class<? extends U> getClass(String name, 
                                         Class<? extends U> defaultValue, 
                                         Class<U> xface); @SuppressWarnings("unchecked") List<U> getInstances(String name, Class<U> xface); void setClass(String name, Class<?> theClass, Class<?> xface); Path getLocalPath(String dirsProp, String path); File getFile(String dirsProp, String path); URL getResource(String name); InputStream getConfResourceAsInputStream(String name); Reader getConfResourceAsReader(String name); Set<String> getFinalParameters(); int size(); void clear(); @Override Iterator<Map.Entry<String, String>> iterator(); Map<String, String> getPropsWithPrefix(String confPrefix); void addTags(Properties prop); void writeXml(OutputStream out); void writeXml(Writer out); void writeXml(@Nullable String propertyName, Writer out); static void dumpConfiguration(Configuration config,
      String propertyName, Writer out); static void dumpConfiguration(Configuration config,
      Writer out); ClassLoader getClassLoader(); void setClassLoader(ClassLoader classLoader); @Override String toString(); synchronized void setQuietMode(boolean quietmode); static void main(String[] args); @Override void readFields(DataInput in); @Override void write(DataOutput out); Map<String,String> getValByRegex(String regex); static void dumpDeprecatedKeys(); static boolean hasWarnedDeprecation(String name); Properties getAllPropertiesByTag(final String tag); Properties getAllPropertiesByTags(final List<String> tagList); boolean isPropertyTag(String tagStr);  }
@Test public void testGetValByRegex() { Configuration conf = new Configuration(); String key1 = "t.abc.key1"; String key2 = "t.abc.key2"; String key3 = "tt.abc.key3"; String key4 = "t.abc.ey3"; conf.set(key1, "value1"); conf.set(key2, "value2"); conf.set(key3, "value3"); conf.set(key4, "value3"); Map<String,String> res = conf.getValByRegex("^t\\..*\\.key\\d"); assertTrue("Conf didn't get key " + key1, res.containsKey(key1)); assertTrue("Conf didn't get key " + key2, res.containsKey(key2)); assertTrue("Picked out wrong key " + key3, !res.containsKey(key3)); assertTrue("Picked out wrong key " + key4, !res.containsKey(key4)); }