Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java36
1 files changed, 35 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
index f882d49ed1..af04b10901 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
@@ -387,6 +387,13 @@ public class Config {
if (value == null)
return defaultValue;
+ if (all[0] instanceof ConfigEnum) {
+ for (T t : all) {
+ if (((ConfigEnum) t).matchConfigValue(value))
+ return t;
+ }
+ }
+
String n = value.replace(' ', '_');
// Because of c98abc9c0586c73ef7df4172644b7dd21c979e9d being used in
@@ -728,7 +735,11 @@ public class Config {
*/
public <T extends Enum<?>> void setEnum(final String section,
final String subsection, final String name, final T value) {
- String n = value.name().toLowerCase().replace('_', ' ');
+ String n;
+ if (value instanceof ConfigEnum)
+ n = ((ConfigEnum) value).toConfigValue();
+ else
+ n = value.name().toLowerCase().replace('_', ' ');
setString(section, subsection, name, n);
}
@@ -1275,4 +1286,27 @@ public class Config {
pos--;
}
}
+
+ /**
+ * Converts enumeration values into configuration options and vice-versa,
+ * allowing to match a config option with an enum value.
+ *
+ */
+ public static interface ConfigEnum {
+ /**
+ * Converts enumeration value into a string to be save in config.
+ *
+ * @return the enum value as config string
+ */
+ String toConfigValue();
+
+ /**
+ * Checks if the given string matches with enum value.
+ *
+ * @param in
+ * the string to match
+ * @return true if the given string matches enum value, false otherwise
+ */
+ boolean matchConfigValue(String in);
+ }
}

Back to the top