@Test public void testGetSection() { properties.setProperty("prop.test1", "1"); properties.setProperty("prop.test2", "2"); properties.setProperty("prop_test3", "3"); properties.setProperty("prop_test4", "4"); properties.setProperty("prop.test5", "5"); ConfigObject actual = configObject.getSection("prop"); assertNotNull(actual); assertEquals(3, actual.getProperties().size()); assertEquals("2", actual.get("test2")); assertNull(configObject.getSection("")); }
public ConfigObject getSection(String prefix) { Set<String> props = config.stringPropertyNames(); Properties child = new Properties(); String s = prefix + '.'; for (String prop : props) { if (prop.startsWith(s)) { String newProp = StringUtil.lchop(prop, s); child.setProperty(newProp, $(prop)); } } if (child.isEmpty()) { return null; } if (section == StringUtil.EMPTY) { return new ConfigObject(prefix, child); } String newSection = section + '.' + prefix; return new ConfigObject(newSection, child); }
ConfigObject { public ConfigObject getSection(String prefix) { Set<String> props = config.stringPropertyNames(); Properties child = new Properties(); String s = prefix + '.'; for (String prop : props) { if (prop.startsWith(s)) { String newProp = StringUtil.lchop(prop, s); child.setProperty(newProp, $(prop)); } } if (child.isEmpty()) { return null; } if (section == StringUtil.EMPTY) { return new ConfigObject(prefix, child); } String newSection = section + '.' + prefix; return new ConfigObject(newSection, child); } }
ConfigObject { public ConfigObject getSection(String prefix) { Set<String> props = config.stringPropertyNames(); Properties child = new Properties(); String s = prefix + '.'; for (String prop : props) { if (prop.startsWith(s)) { String newProp = StringUtil.lchop(prop, s); child.setProperty(newProp, $(prop)); } } if (child.isEmpty()) { return null; } if (section == StringUtil.EMPTY) { return new ConfigObject(prefix, child); } String newSection = section + '.' + prefix; return new ConfigObject(newSection, child); } ConfigObject(File propertiesFile);  ConfigObject(InputStream is);  ConfigObject(String path);  ConfigObject(Properties props); private  ConfigObject(String section, Properties props); private  String(String property); }
ConfigObject { public ConfigObject getSection(String prefix) { Set<String> props = config.stringPropertyNames(); Properties child = new Properties(); String s = prefix + '.'; for (String prop : props) { if (prop.startsWith(s)) { String newProp = StringUtil.lchop(prop, s); child.setProperty(newProp, $(prop)); } } if (child.isEmpty()) { return null; } if (section == StringUtil.EMPTY) { return new ConfigObject(prefix, child); } String newSection = section + '.' + prefix; return new ConfigObject(newSection, child); } ConfigObject(File propertiesFile);  ConfigObject(InputStream is);  ConfigObject(String path);  ConfigObject(Properties props); private  ConfigObject(String section, Properties props); private  String(String property); static ConfigObject forResource(String resource); static boolean isTrueValue(String value); static boolean isTrueValue(String value, boolean dfault); static boolean isEnabled(String propName); static boolean isEnabled(Properties config, String propName); static boolean isEnabled(String propName, boolean dfault); static boolean isEnabled(Properties config, String propName, boolean dfault); boolean hasProperty(String property); List<String> getPropertyNames(); Properties getProperties(); String get(String property); int getInt(String property); String get(String property, String dfault); String get(String property, boolean emptyIsNull); String get(String property, String dfault, boolean emptyIsDefault); boolean isTrue(String property); boolean isTrue(String property, boolean dfault); String required(String property); @SuppressWarnings("unchecked") T required(String property, Class<T> castTo); File getFile(String property); File getDirectory(String property); Path getPath(String property); String[] getArray(String property); String[] getArray(String property, char separator); String[] requiredArray(String property); String[] requiredArray(String property, char separator); String getParentSection(); ConfigObject getSection(String prefix); boolean hasSection(String prefix); String[] getSubsections(); String[] getSubsections(String parentSection); void set(String property, String value); }
ConfigObject { public ConfigObject getSection(String prefix) { Set<String> props = config.stringPropertyNames(); Properties child = new Properties(); String s = prefix + '.'; for (String prop : props) { if (prop.startsWith(s)) { String newProp = StringUtil.lchop(prop, s); child.setProperty(newProp, $(prop)); } } if (child.isEmpty()) { return null; } if (section == StringUtil.EMPTY) { return new ConfigObject(prefix, child); } String newSection = section + '.' + prefix; return new ConfigObject(newSection, child); } ConfigObject(File propertiesFile);  ConfigObject(InputStream is);  ConfigObject(String path);  ConfigObject(Properties props); private  ConfigObject(String section, Properties props); private  String(String property); static ConfigObject forResource(String resource); static boolean isTrueValue(String value); static boolean isTrueValue(String value, boolean dfault); static boolean isEnabled(String propName); static boolean isEnabled(Properties config, String propName); static boolean isEnabled(String propName, boolean dfault); static boolean isEnabled(Properties config, String propName, boolean dfault); boolean hasProperty(String property); List<String> getPropertyNames(); Properties getProperties(); String get(String property); int getInt(String property); String get(String property, String dfault); String get(String property, boolean emptyIsNull); String get(String property, String dfault, boolean emptyIsDefault); boolean isTrue(String property); boolean isTrue(String property, boolean dfault); String required(String property); @SuppressWarnings("unchecked") T required(String property, Class<T> castTo); File getFile(String property); File getDirectory(String property); Path getPath(String property); String[] getArray(String property); String[] getArray(String property, char separator); String[] requiredArray(String property); String[] requiredArray(String property, char separator); String getParentSection(); ConfigObject getSection(String prefix); boolean hasSection(String prefix); String[] getSubsections(); String[] getSubsections(String parentSection); void set(String property, String value);  }