fork download
  1. import java.util.*;
  2.  
  3. enum KeyFinder {
  4. A(1, "a", "a", "A"),
  5. TILDE(2, "~", "~", "`");
  6.  
  7. private static final Map<String, KeyFinder> lookup = new LinkedHashMap<String, KeyFinder>();
  8.  
  9. static {
  10. for (KeyFinder type : EnumSet.allOf(KeyFinder.class)) {
  11. for (String key : type.lookupKeys) {
  12. lookup.put(key, type);
  13. }
  14. }
  15. }
  16.  
  17.  
  18. private final int key;
  19. private final String keyName;
  20. private final String[] lookupKeys;
  21.  
  22. KeyFinder(int key, String keyName, String... lookupKeys) {
  23. this.key = key;
  24. this.keyName = keyName;
  25. this.lookupKeys = lookupKeys;
  26. }
  27.  
  28. public static void main(String[] args) {
  29. System.out.println(lookup);
  30. System.out.println(lookup.get("a"));
  31. System.out.println(lookup.get("~"));
  32. }
  33. }
Success #stdin #stdout 0.03s 245632KB
stdin
stdout
{a=A, A=A, ~=TILDE, `=TILDE}
A
TILDE