key.validator.ensureValid(key.name, value); } catch (ConfigException e) { config.addErrorMessage(e.getMessage());
default ValidatorWithOperators and(ConfigDef.Validator other) { return (name, value) -> { this.ensureValid(name, value); other.ensureValid(name, value); }; } }
default ValidatorWithOperators or(ConfigDef.Validator other) { return (name, value) -> { try { this.ensureValid(name, value); } catch (ConfigException e) { other.ensureValid(name, value); } }; }
default ValidatorWithOperators and(ConfigDef.Validator other) { return (name, value) -> { this.ensureValid(name, value); other.ensureValid(name, value); }; } }
@Override public void ensureValid(String key, Object o) { if (o instanceof String) { final String s = o.toString(); if (!Strings.isNullOrEmpty(s)) { validator.ensureValid(key, o); } } }
default ValidatorWithOperators or(ConfigDef.Validator other) { return (name, value) -> { try { this.ensureValid(name, value); } catch (ConfigException e) { other.ensureValid(name, value); } }; }
public ConfigKey(String name, Type type, Object defaultValue, Validator validator, Importance importance, String documentation) { super(); this.name = name; this.type = type; this.defaultValue = defaultValue; this.validator = validator; this.importance = importance; if (this.validator != null) this.validator.ensureValid(name, defaultValue); this.documentation = documentation; }
@Override public Object parseValue(final Object value) { final Object parsed = ConfigDef.parseType(key.name, value, key.type); if (key.validator != null) { key.validator.ensureValid(key.name, parsed); } return parsed; }
public ConfigKey(String name, Type type, Object defaultValue, Validator validator, Importance importance, String documentation, String group, int orderInGroup, Width width, String displayName, List<String> dependents, Recommender recommender, boolean internalConfig) { this.name = name; this.type = type; this.defaultValue = NO_DEFAULT_VALUE.equals(defaultValue) ? NO_DEFAULT_VALUE : parseType(name, defaultValue, type); this.validator = validator; this.importance = importance; if (this.validator != null && hasDefault()) this.validator.ensureValid(name, this.defaultValue); this.documentation = documentation; this.dependents = dependents; this.group = group; this.orderInGroup = orderInGroup; this.width = width; this.displayName = displayName; this.recommender = recommender; this.internalConfig = internalConfig; }
Object parseValue(ConfigKey key, Object value, boolean isSet) { Object parsedValue; if (isSet) { parsedValue = parseType(key.name, value, key.type); // props map doesn't contain setting, the key is required because no default value specified - its an error } else if (NO_DEFAULT_VALUE.equals(key.defaultValue)) { throw new ConfigException("Missing required configuration \"" + key.name + "\" which has no default value."); } else { // otherwise assign setting its default value parsedValue = key.defaultValue; } if (key.validator != null) { key.validator.ensureValid(key.name, parsedValue); } return parsedValue; }
/** * Returns a new validator instance that delegates to the base validator but unprefixes the config name along the way. */ private static Validator embeddedValidator(final String keyPrefix, final Validator base) { if (base == null) return null; return (name, value) -> base.ensureValid(name.substring(keyPrefix.length()), value); }
@Override public void ensureValid(String name, Object value) { for (Validator validator: validators) { validator.ensureValid(name, value); } }