From c2f888d9acd5f58e8bf18b083db46605a1f4ede2 Mon Sep 17 00:00:00 2001 From: Decebal Suiu Date: Thu, 24 May 2018 22:13:42 +0300 Subject: [PATCH] Add aliases to the runtime modes --- pf4j/src/main/java/org/pf4j/RuntimeMode.java | 33 +++++++++++--------- 1 file 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 map = new HashMap<>(); + private static final Map 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() + "."); } }