protected String getConfigValue(ConfigKey key, String headerName) { switch (headerName) { case "Name": return key.name; case "Description": return key.documentation; case "Type": return key.type.toString().toLowerCase(Locale.ROOT); case "Default": if (key.hasDefault()) { if (key.defaultValue == null) return "null"; String defaultValueStr = convertToString(key.defaultValue, key.type); if (defaultValueStr.isEmpty()) return "\"\""; else return defaultValueStr; } else return ""; case "Valid Values": return key.validator != null ? key.validator.toString() : ""; case "Importance": return key.importance.toString().toLowerCase(Locale.ROOT); default: throw new RuntimeException("Can't find value for header '" + headerName + "' in " + key.name); } }
/** * Define a new internal configuration. Internal configuration won't show up in the docs and aren't * intended for general use. * @param name The name of the config parameter * @param type The type of the config * @param defaultValue The default value to use if this config isn't present * @param importance * @return This ConfigDef so you can chain calls */ public ConfigDef defineInternal(final String name, final Type type, final Object defaultValue, final Importance importance) { return define(new ConfigKey(name, type, defaultValue, null, importance, "", "", -1, Width.NONE, name, Collections.<String>emptyList(), null, true)); }
/** * Define a new configuration * @param name The name of the config parameter * @param type The type of the config * @param defaultValue The default value to use if this config isn't present * @param validator A validator to use in checking the correctness of the config * @param importance The importance of this config: is this something you will likely need to change. * @param documentation The documentation string for the config * @return This ConfigDef so you can chain calls */ public ConfigDef define(String name, Type type, Object defaultValue, Validator validator, Importance importance, String documentation) { if (configKeys.containsKey(name)) throw new ConfigException("Configuration " + name + " is defined twice."); Object parsedDefault = defaultValue == NO_DEFAULT_VALUE ? NO_DEFAULT_VALUE : parseType(name, defaultValue, type); configKeys.put(name, new ConfigKey(name, type, parsedDefault, validator, importance, documentation)); return this; }
public int compare(ConfigDef.ConfigKey k1, ConfigDef.ConfigKey k2) { // first take anything with no default value (therefore required) if (!k1.hasDefault() && k2.hasDefault()) return -1; else if (!k2.hasDefault() && k1.hasDefault()) return 1; // then sort by importance int cmp = k1.importance.compareTo(k2.importance); if (cmp == 0) // then sort in alphabetical order return k1.name.compareTo(k2.name); else return cmp; } });
public int compare(ConfigDef.ConfigKey k1, ConfigDef.ConfigKey k2) { // first take anything with no default value if (!k1.hasDefault() && k2.hasDefault()) return -1; else if (!k2.hasDefault() && k1.hasDefault()) return 1; // then sort by importance int cmp = k1.importance.compareTo(k2.importance); if (cmp == 0) // then sort in alphabetical order return k1.name.compareTo(k2.name); else return cmp; } });
public int compare(ConfigDef.ConfigKey k1, ConfigDef.ConfigKey k2) { // first take anything with no default value (therefore required) if (!k1.hasDefault() && k2.hasDefault()) return -1; else if (!k2.hasDefault() && k1.hasDefault()) return 1; // then sort by importance int cmp = k1.importance.compareTo(k2.importance); if (cmp == 0) // then sort in alphabetical order return k1.name.compareTo(k2.name); else return cmp; } });
public ConfigDef.ConfigKey build() { Preconditions.checkState(!Strings.isNullOrEmpty(this.name), "name must be specified."); return new ConfigDef.ConfigKey(this.name, this.type, this.defaultValue, this.validator, this.importance, this.documentation, this.group, this.orderInGroup, this.width, this.displayName, this.dependents, this.recommender, this.internalConfig); }
static String getDefaultValue(ConfigDef.ConfigKey def) { if (def.hasDefault()) { if (def.defaultValue == null) return "null"; else if (def.type == ConfigDef.Type.STRING && def.defaultValue.toString().isEmpty()) return "\"\""; else return def.defaultValue.toString(); } else return ""; }
static String getDefaultValue(ConfigDef.ConfigKey def) { if (def.hasDefault()) { if (def.defaultValue == null) return "null"; else if (def.type == ConfigDef.Type.STRING && def.defaultValue.toString().isEmpty()) return "\"\""; else return def.defaultValue.toString(); } else return ""; }
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; }
private int compare(ConfigKey k1, ConfigKey k2, Map<String, Integer> groupOrd) { int cmp = k1.group == null ? (k2.group == null ? 0 : -1) : (k2.group == null ? 1 : Integer.compare(groupOrd.get(k1.group), groupOrd.get(k2.group))); if (cmp == 0) { cmp = Integer.compare(k1.orderInGroup, k2.orderInGroup); if (cmp == 0) { // first take anything with no default value if (!k1.hasDefault() && k2.hasDefault()) cmp = -1; else if (!k2.hasDefault() && k1.hasDefault()) cmp = 1; else { cmp = k1.importance.compareTo(k2.importance); if (cmp == 0) return k1.name.compareTo(k2.name); } } } return cmp; }
/** * Define a new configuration * @param name the name of the config parameter * @param type the type of the config * @param defaultValue the default value to use if this config isn't present * @param validator the validator to use in checking the correctness of the config * @param importance the importance of this config * @param documentation the documentation string for the config * @param group the group this config belongs to * @param orderInGroup the order of this config in the group * @param width the width of the config * @param displayName the name suitable for display * @param dependents the configurations that are dependents of this configuration * @param recommender the recommender provides valid values given the parent configuration values * @return This ConfigDef so you can chain calls */ public ConfigDef define(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) { return define(new ConfigKey(name, type, defaultValue, validator, importance, documentation, group, orderInGroup, width, displayName, dependents, recommender, false)); }
/** * Shared content on Rst and Enriched Rst. */ private void getConfigKeyRst(ConfigKey key, StringBuilder b) { b.append("``").append(key.name).append("``").append("\n"); for (String docLine : key.documentation.split("\n")) { if (docLine.length() == 0) { continue; } b.append(" ").append(docLine).append("\n\n"); } b.append(" * Type: ").append(getConfigValue(key, "Type")).append("\n"); if (key.hasDefault()) { b.append(" * Default: ").append(getConfigValue(key, "Default")).append("\n"); } if (key.validator != null) { b.append(" * Valid Values: ").append(getConfigValue(key, "Valid Values")).append("\n"); } b.append(" * Importance: ").append(getConfigValue(key, "Importance")).append("\n"); }