diff options
author | Decebal Suiu <decebal.suiu@gmail.com> | 2018-05-24 22:13:42 +0300 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2018-05-24 22:13:42 +0300 |
commit | c2f888d9acd5f58e8bf18b083db46605a1f4ede2 (patch) | |
tree | d441a47fe1bd32f9587647ef90ce7ba582989ca2 /pf4j | |
parent | 6b13884408370c3552d9c5086fbac0a3f8b10ff0 (diff) | |
download | pf4j-c2f888d9acd5f58e8bf18b083db46605a1f4ede2.tar.gz pf4j-c2f888d9acd5f58e8bf18b083db46605a1f4ede2.zip |
Add aliases to the runtime modes
Diffstat (limited to 'pf4j')
-rw-r--r-- | pf4j/src/main/java/org/pf4j/RuntimeMode.java | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/pf4j/src/main/java/org/pf4j/RuntimeMode.java b/pf4j/src/main/java/org/pf4j/RuntimeMode.java index 0ab8abe..1fa9cbd 100644 --- a/pf4j/src/main/java/org/pf4j/RuntimeMode.java +++ b/pf4j/src/main/java/org/pf4j/RuntimeMode.java @@ -24,21 +24,26 @@ import java.util.NoSuchElementException; */ public enum RuntimeMode { - DEVELOPMENT("development"), // development - DEPLOYMENT("deployment"); // deployment + DEVELOPMENT("development", "dev"), // development + DEPLOYMENT("deployment", "prod"); // deployment private final String name; + private final String[] aliases; - private static final Map<String, RuntimeMode> map = new HashMap<>(); + private static final Map<String, RuntimeMode> map = new HashMap<>(); - static { - for (RuntimeMode mode : RuntimeMode.values()) { - map.put(mode.name, mode); - } - } + static { + for (RuntimeMode mode : RuntimeMode.values()) { + map.put(mode.name, mode); + for (String alias : mode.aliases) { + map.put(alias, mode); + } + } + } - private RuntimeMode(final String name) { + private RuntimeMode(final String name, final String... aliases) { this.name = name; + this.aliases = aliases; } @Override @@ -47,12 +52,12 @@ public enum RuntimeMode { } public static RuntimeMode byName(String name) { - if (map.containsKey(name)) { - return map.get(name); - } + if (map.containsKey(name)) { + return map.get(name); + } - throw new NoSuchElementException("Cannot found PF4J runtime mode with name '" + name + - "'. Must be 'development' or 'deployment'."); + throw new NoSuchElementException("Cannot found PF4J runtime mode with name '" + name + "'." + + "Must be one value from '" + map.keySet() + "."); } } |