1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;
public abstract class StandardType { private String key; private String title;
public StandardType(String key, String title) { this.title = title; this.key = key; }
public String getTitle() { return title; }
public static String getTitle(StandardType[] values, String key) { StandardType val = StandardType.getEnum(values, key); if (val == null) { return null; } else { return val.getTitle(); } }
public String getKey() { return key; }
public static String getKey(StandardType[] values, String title) { for (StandardType val : values) { if (val.getTitle().equals(title)) { return val.getKey(); } } return null; }
public static StandardType getEnum(StandardType[] values, String key) { for (StandardType val : values) { if (val.getKey().equals(key)) { return val; } } return null; }
public String toString() { return key; }
public boolean equals(StandardType type) { if (type == null) { return false; } return this.key.equals(type.getKey()); }
/** * get value options based on values * * @param values * @return */ public static List<Map<String, String>> getOpts(StandardType[] values) { List<Map<String, String>> opts = new ArrayList<Map<String, String>>(); Map<String, String> opt = null; for (StandardType val : values) { opt = new HashMap<String, String>(); opt.put("key", val.getKey()); opt.put("title", val.getTitle()); opts.add(opt); } return opts; }
/** * get value options based on values(Fuzzy query) * * @param values * @return */ public static List<Map<String, String>> getSimilarOpts(StandardType[] values, String input) { List<Map<String, String>> opts = new ArrayList<Map<String, String>>(); Map<String, String> opt = null; for (StandardType val : values) { if (val.getTitle().contains(input)) { opt = new HashMap<String, String>(); opt.put("key", val.getKey()); opt.put("title", val.getTitle()); opts.add(opt); } } return opts; } }
|