/** * Converts this ConfigObject ino the java.util.Properties format, flatten the tree and prefixing all entries with the given prefix * * @param prefix The prefix to append before property entries * @return A java.util.Properties instance */ public Properties toProperties(String prefix) { Properties props = new Properties(); populate(prefix + ".", props, this); props = convertValuesToString(props); return props; }
private void populate(String suffix, Map config, Map map) { for (Object o : map.entrySet()) { Map.Entry next = (Map.Entry) o; Object key = next.getKey(); Object value = next.getValue(); if (value instanceof Map) { populate(suffix + key + ".", config, (Map) value); } else { try { config.put(suffix + key, value); } catch (NullPointerException e) { // it is idiotic story but if config map doesn't allow null values (like Hashtable) // we can't do too much } } } }
/** * Flattens this ConfigObject populating the results into the target Map * * @see ConfigObject#flatten() */ public Map flatten(Map target) { if (target == null) target = new ConfigObject(); populate("", target, this); return target; }
private void populate(String suffix, Map config, Map map) { for (Object o : map.entrySet()) { Map.Entry next = (Map.Entry) o; String key = (String) next.getKey(); Object value = next.getValue(); if (value instanceof Map) { populate(suffix + key + ".", config, (Map) value); } else { try { config.put(suffix + key, value); } catch (NullPointerException e) { // it is idiotic story but if config map doesn't allow null values (like Hashtable) // we can't do too much } } } }
/** * Converts this ConfigObject ino the java.util.Properties format, flatten the tree and prefixing all entries with the given prefix * * @param prefix The prefix to append before property entries * @return A java.util.Properties instance */ public Properties toProperties(String prefix) { Properties props = new Properties(); populate(prefix + ".", props, this); props = convertValuesToString(props); return props; }
/** * Flattens this ConfigObject populating the results into the target Map * * @see ConfigObject#flatten() */ public Map flatten(Map target) { if (target == null) target = new ConfigObject(); populate("", target, this); return target; }