@Override public synchronized Object put(Object key, Object value) { // ugly way to load them in order // (Properties is a hashtable so loses order otherwise) return BrooklynProperties.this.put(key, value); } };
/** like normal map.putAll, except config keys are dereferenced on the way in */ @Override public void putAll(Map vals) { for (Map.Entry<?,?> entry : ((Map<?,?>)vals).entrySet()) { put(entry.getKey(), entry.getValue()); } }
/** inserts the value under the given key, if it was not present */ public boolean putIfAbsent(String key, Object value) { if (containsKey(key)) return false; put(key, value); return true; }
/** prefix generally ends with a full stop */ public static BrooklynProperties filterForPrefixAndStrip(Map<String,?> properties, String prefix) { BrooklynProperties result = BrooklynProperties.Factory.newEmpty(); for (String k: properties.keySet()) { if (k.startsWith(prefix)) { result.put(k.substring(prefix.length()), properties.get(k)); } } return result; }
@Override public BrooklynProperties submap(Predicate<ConfigKey<?>> filter) { BrooklynProperties result = Factory.newEmpty(); for (Object entry: entrySet()) { ConfigKey<?> k = new BasicConfigKey<Object>(Object.class, ""+((Map.Entry)entry).getKey()); if (filter.apply(k)) result.put(((Map.Entry)entry).getKey(), ((Map.Entry)entry).getValue()); } return result; }
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; }
brooklynProperties.put(entry.getKey(), entry.getValue());