/** gets all the keys in the given config bag which are applicable to the given list of parameters */ public static List<FlagConfigKeyAndValueRecord> findAllParameterConfigKeys(List<SpecParameter<?>> parameters, ConfigBag input) { List<FlagConfigKeyAndValueRecord> output = new ArrayList<FlagUtils.FlagConfigKeyAndValueRecord>(); for (SpecParameter<?> param : parameters) { FlagConfigKeyAndValueRecord record = getFlagConfigKeyRecord(null, param.getConfigKey(), input); if (record.isValuePresent()) output.add(record); } return output; }
/** gets all the flags/keys in the given config bag which are applicable to the given type's config keys and flags */ public static <T> List<FlagConfigKeyAndValueRecord> findAllFlagsAndConfigKeys(T optionalInstance, Class<? extends T> type, ConfigBag input) { List<FlagConfigKeyAndValueRecord> output = new ArrayList<FlagUtils.FlagConfigKeyAndValueRecord>(); for (Field f: getAllFields(type)) { ConfigKey<?> key = getFieldAsConfigKey(optionalInstance, f); FlagConfigKeyAndValueRecord record = getFlagConfigKeyRecord(f, key, input); if (record.isValuePresent()) output.add(record); } return output; }
/** sets _all_ accessible _{@link ConfigKey}_ and {@link HasConfigKey} fields on the given object, * using the indicated flags/config-bag */ public static void setAllConfigKeys(Configurable o, ConfigBag bag, boolean includeFlags) { for (Field f: getAllFields(o.getClass())) { ConfigKey<?> key = getFieldAsConfigKey(o, f); if (key!=null) { FlagConfigKeyAndValueRecord record = getFlagConfigKeyRecord(f, key, bag); if ((includeFlags && record.isValuePresent()) || record.getConfigKeyMaybeValue().isPresent()) { setField(o, f, record.getValueOrNullPreferringConfigKey(), null); } } } }