/** * Checks if a config option is set. Example usage: * <pre class="groovyTestCase"> * def config = new ConfigSlurper().parse("foo { password='' }") * assert config.foo.isSet('password') * assert config.foo.isSet('username') == false * </pre> * * The check works <b>only</v> for options <b>one</b> block below the current block. * E.g. <code>config.isSet('foo.password')</code> will always return false. * * @param option The name of the option * @return <code>true</code> if the option is set <code>false</code> otherwise * @since 2.3.0 */ public Boolean isSet(String option) { if (delegateMap.containsKey(option)) { Object entry = delegateMap.get(option); if (!(entry instanceof ConfigObject) || !((ConfigObject) entry).isEmpty()) { return Boolean.TRUE; } } return Boolean.FALSE; }
ConfigObject value = (ConfigObject) v; if (!value.isEmpty()) {
@Nullable @Override @SuppressWarnings("unchecked") protected Object handleGetObject(@Nonnull String key) { Object value = getConfigValue(config, requireNonBlank(key, "Argument 'key' must not be blank"), null); if (null == value) return null; if (value instanceof ConfigObject) { return ((ConfigObject) value).isEmpty() ? null : value; } return value; }
private static void createFlatConfig(ConfigObject currentConfigObject, Map<String, Object> rootConfig, String prefix) { Set keySet = currentConfigObject.keySet(); for (Object key : keySet) { Object value = currentConfigObject.get(key); if(value instanceof ConfigObject) { ConfigObject sub = ((ConfigObject) value).clone(); String fullPath = prefix + key; if(!sub.isEmpty()) { Map flattened = sub.flatten(); sub.putAll(flattened); createFlatConfig(sub, rootConfig, fullPath + "."); if(!rootConfig.containsKey(fullPath)) { rootConfig.put(fullPath, sub); } } } else { rootConfig.put(prefix + key, value); } } }
/** * * @param co current config object which is queried * @param currentNamePart the queried property name * @return the value for given property name * @throws ObjectNotFoundException */ private Object configObjectGet(ConfigObject co, String currentNamePart) { /* * get the property value */ Object result = co.getProperty(currentNamePart); if (result instanceof ConfigObject) { // try if property value is empty ConfigObject coResult = (ConfigObject) result; if (coResult.isEmpty()) { throw new ObjectNotFoundException(); } } else { result = resolvePropObject(result); }// fi return result; }
ConfigObject value = (ConfigObject) v; if (!value.isEmpty()) {