protected String getPath(ConfigElement option, String... umbrellaElements) { verifyElement(option); return ConfigElement.getPath(option,umbrellaElements); }
protected void verifyOption(ConfigOption option) { Preconditions.checkNotNull(option); super.verifyElement(option); if (restriction==Restriction.GLOBAL) Preconditions.checkArgument(option.isGlobal(),"Can only accept global options: %s",option); else if (restriction==Restriction.LOCAL) Preconditions.checkArgument(option.isLocal(),"Can only accept local options: %s",option); }
protected Set<String> getContainedNamespaces(ReadConfiguration config, ConfigNamespace umbrella, String... umbrellaElements) { verifyElement(umbrella); Preconditions.checkArgument(umbrella.isUmbrella()); String prefix = ConfigElement.getPath(umbrella,umbrellaElements); Set<String> result = Sets.newHashSet(); for (String key : config.getKeys(prefix)) { Preconditions.checkArgument(key.startsWith(prefix)); String sub = key.substring(prefix.length()+1).trim(); if (!sub.isEmpty()) { String ns = ConfigElement.getComponents(sub)[0]; Preconditions.checkArgument(StringUtils.isNotBlank(ns),"Invalid sub-namespace for key: %s",key); result.add(ns); } } return result; }
protected Map<String,Object> getSubset(ReadConfiguration config, ConfigNamespace umbrella, String... umbrellaElements) { verifyElement(umbrella); String prefix = umbrella.isRoot() ? "" : ConfigElement.getPath(umbrella, umbrellaElements); Map<String,Object> result = Maps.newHashMap(); for (String key : config.getKeys(prefix)) { Preconditions.checkArgument(key.startsWith(prefix)); // A zero-length prefix is a root. A positive-length prefix // is not a root and we should tack on an additional character // to consume the dot between the prefix and the rest of the key. int startIndex = umbrella.isRoot() ? prefix.length() : prefix.length() + 1; String sub = key.substring(startIndex).trim(); if (!sub.isEmpty()) { result.put(sub,config.get(key,Object.class)); } } return result; }