public boolean isSubKey(ConfigKey<?> contender) { return (contender instanceof SubElementConfigKey && this.equals(((SubElementConfigKey<?>) contender).parent)); }
@Override public boolean isSubKey(Object contender) { return contender instanceof ConfigKey && isSubKey((ConfigKey<?>)contender); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Object applyValueToMap(Object value, Map target) { if (value instanceof StructuredModification) { return ((StructuredModification)value).applyToKeyInMap(this, target); } else if (value instanceof Collection) { String warning = "Discouraged undecorated setting of a collection to ListConfigKey "+this+": use ListModification.{set,add}. " + "Defaulting to 'add'. Look at debug logging for call stack."; log.warn(warning); if (log.isDebugEnabled()) log.debug("Trace for: "+warning, new Throwable("Trace for: "+warning)); for (Object v: (Collection)value) applyValueToMap(v, target); return null; } else { // just add to list, using anonymous key target.put(subKey(), value); return null; } }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Object applyToKeyInMap(ListConfigKey<T> key, Map target) { if (clearFirst) { StructuredModification<StructuredConfigKey> clearing = StructuredModifications.clearing(); clearing.applyToKeyInMap(key, target); } for (T o: this) target.put(key.subKey(), o); return null; } }
@Override public boolean isSet(Map<?, ?> vals) { if (vals.containsKey(this)) return true; for (Object contender : vals.keySet()) { if (isSubKey(contender)) { return true; } } return false; }
@Override @SuppressWarnings("unchecked") public List<V> extractValue(Map<?,?> vals, ExecutionContext exec) { List<V> result = Lists.newArrayList(); for (Object k : vals.keySet()) { if (isSubKey(k)) result.add( ((SubElementConfigKey<V>) k).extractValue(vals, exec) ); } return Collections.unmodifiableList(result); }