@Override public Set<String> getContainedNamespaces(ConfigNamespace umbrella, String... umbrellaElements) { return super.getContainedNamespaces(config,umbrella,umbrellaElements); }
@Override public Map<String, Object> getSubset(ConfigNamespace umbrella, String... umbrellaElements) { return super.getSubset(config,umbrella,umbrellaElements); }
protected String getPath(ConfigElement option, String... umbrellaElements) { verifyElement(option); return ConfigElement.getPath(option,umbrellaElements); }
@Override public boolean has(ConfigOption option, String... umbrellaElements) { verifyOption(option); return config.get(super.getPath(option,umbrellaElements),option.getDatatype())!=null; }
@Override public<O> O get(ConfigOption<O> option, String... umbrellaElements) { verifyOption(option); O result = config.get(super.getPath(option,umbrellaElements),option.getDatatype()); return option.get(result); }
@Override public boolean has(ConfigOption option, String... umbrellaElements) { final String key = super.getPath(option, umbrellaElements); return option.isLocal() && local.get(key, option.getDatatype()) != null || option.isGlobal() && global.get(key, option.getDatatype()) != null; }
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); }
@Override public Set<String> getContainedNamespaces(ConfigNamespace umbrella, String... umbrellaElements) { return Arrays.stream(new ReadConfiguration[]{global,local}) .map(config -> super.getContainedNamespaces(config, umbrella, umbrellaElements)) .flatMap(Set::stream) .collect(Collectors.toSet()); }
public Map<String,Object> getSubset(ConfigNamespace umbrella, String... umbrellaElements) { Map<String,Object> result = Maps.newHashMap(); for (ReadConfiguration config : new ReadConfiguration[]{global,local}) { result.putAll(super.getSubset(config,umbrella,umbrellaElements)); } return result; }
@Override public<O> O get(ConfigOption<O> option, String... umbrellaElements) { final String key = super.getPath(option,umbrellaElements); Object result = null; if (option.isLocal()) { result = local.get(key,option.getDatatype()); } if (result==null && option.isGlobal()) { result = global.get(key,option.getDatatype()); } return option.get(result); }
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; }