/** expects a property already set in scope, whose value is acceptable to {@link #addFromUrl(String)}; * if property not set, does nothing */ public BrooklynProperties addFromUrlProperty(String urlProperty) { String url = (String) get(urlProperty); if (url==null) addFromUrl(url); return this; }
@Override public Object getRawConfig(ConfigKey<?> key) { return get(key.getName()); }
@Override public String getFirst(Map flags, String ...keys) { for (String k: keys) { if (k!=null && containsKey(k)) return (String) get(k); } if (flags.get("warnIfNone")!=null && !Boolean.FALSE.equals(flags.get("warnIfNone"))) { if (Boolean.TRUE.equals(flags.get("warnIfNone"))) LOG.warn("Unable to find Brooklyn property "+keys); else LOG.warn(""+flags.get("warnIfNone")); } if (flags.get("failIfNone")!=null && !Boolean.FALSE.equals(flags.get("failIfNone"))) { Object f = flags.get("failIfNone"); if (f instanceof Closure) ((Closure)f).call((Object[])keys); if (Boolean.TRUE.equals(f)) throw new NoSuchElementException("Brooklyn unable to find mandatory property "+keys[0]+ (keys.length>1 ? " (or "+(keys.length-1)+" other possible names, full list is "+Arrays.asList(keys)+")" : "") ); else throw new NoSuchElementException(""+f); } if (flags.get("defaultIfNone")!=null) { return (String) flags.get("defaultIfNone"); } return null; }
public static BrooklynProperties filterFor(BrooklynProperties properties, Predicate<? super String> filter) { BrooklynProperties result = BrooklynProperties.Factory.newEmpty(); for (String k: (Collection<String>)properties.keySet()) { if (filter.apply(k)) { result.put(k, properties.get(k)); } } return result; }
public static BrooklynProperties filterForPrefix(BrooklynProperties properties, String prefix) { BrooklynProperties result = BrooklynProperties.Factory.newEmpty(); for (String k: (Collection<String>)properties.keySet()) { if (k.startsWith(prefix)) { result.put(k, properties.get(k)); } } return result; }
@Override public <T> T getConfig(ConfigKey<T> key, T defaultValue) { if (!containsKey(key.getName())) { if (defaultValue!=null) return defaultValue; return key.getDefaultValue(); } Object value = get(key.getName()); if (value==null) return null; // no evaluation / key extraction here return TypeCoercions.coerce(value, key.getTypeToken()); }