You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RuntimeMode.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2013 Decebal Suiu
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.pf4j;
  17. import java.util.HashMap;
  18. import java.util.Map;
  19. import java.util.NoSuchElementException;
  20. /**
  21. * @author Decebal Suiu
  22. */
  23. public enum RuntimeMode {
  24. DEVELOPMENT("development"), // development
  25. DEPLOYMENT("deployment"); // deployment
  26. private final String name;
  27. private static final Map<String, RuntimeMode> map = new HashMap<>();
  28. static {
  29. for (RuntimeMode mode : RuntimeMode.values()) {
  30. map.put(mode.name, mode);
  31. }
  32. }
  33. private RuntimeMode(final String name) {
  34. this.name = name;
  35. }
  36. @Override
  37. public String toString() {
  38. return name;
  39. }
  40. public static RuntimeMode byName(String name) {
  41. if (map.containsKey(name)) {
  42. return map.get(name);
  43. }
  44. throw new NoSuchElementException("Cannot found PF4J runtime mode with name '" + name +
  45. "'. Must be 'development' or 'deployment'.");
  46. }
  47. }