public boolean isSubKey(Object contender) { return contender instanceof ConfigKey && isSubKey((ConfigKey<?>)contender); }
@Override public boolean isSet(Map<?, ?> vals) { if (vals.containsKey(this)) return true; for (Object contender : vals.keySet()) { if (isSubKey(contender)) { return true; } } return false; }
/** returns the entries in the map against this config key and any sub-config-keys, without resolving * (like {@link #extractValue(Map, ExecutionContext)} but without resolving/coercing; * useful because values in this "map" are actually stored against {@link SubElementConfigKey}s */ public Map<String,Object> rawValue(Map<?,?> vals) { Map<String,Object> result = Maps.newLinkedHashMap(); for (Map.Entry<?,?> entry : vals.entrySet()) { Object k = entry.getKey(); if (isSubKey(k)) { @SuppressWarnings("unchecked") SubElementConfigKey<V> subk = (SubElementConfigKey<V>) k; result.put(extractSubKeyName(subk), vals.get(subk)); } } return result; }
@SuppressWarnings({ "rawtypes", "unchecked" }) protected Object applyEntryValueToMap(Entry value, Map target) { Object k = value.getKey(); if (isSubKey(k)) { // do nothing } else if (k instanceof String) { k = subKey((String)k); } else { log.warn("Unexpected subkey "+k+" being inserted into "+this+"; ignoring"); k = null; } if (k!=null) return target.put(k, value.getValue()); else return null; }
@Override public Map<String,V> extractValue(Map<?,?> vals, ExecutionContext exec) { Map<String,V> result = Maps.newLinkedHashMap(); for (Map.Entry<?,?> entry : vals.entrySet()) { Object k = entry.getKey(); if (isSubKey(k)) { @SuppressWarnings("unchecked") SubElementConfigKey<V> subk = (SubElementConfigKey<V>) k; result.put(extractSubKeyName(subk), (V) subk.extractValue(vals, exec)); } } return Collections.unmodifiableMap(result); } /** returns the entries in the map against this config key and any sub-config-keys, without resolving