MCPcopy Create free account
hub / github.com/badvision/jace / findClosestEnumConstant

Method findClosestEnumConstant

src/main/java/jace/core/Utility.java:308–325  ·  view source on GitHub ↗
(String value, Class type)

Source from the content-addressed store, hash-verified

306 static Map<Class, Map<String, Object>> enumCache = new HashMap<>();
307
308 @SuppressWarnings("all")
309 public static Object findClosestEnumConstant(String value, Class type) {
310 Map<String, Object> enumConstants = enumCache.get(type);
311 if (enumConstants == null) {
312 Object[] constants = type.getEnumConstants();
313 enumConstants = new HashMap<>();
314 for (Object o : constants) {
315 enumConstants.put(o.toString(), o);
316 }
317 enumCache.put(type, enumConstants);
318 }
319
320 String key = findBestMatch(value, enumConstants.keySet());
321 if (key == null) {
322 return null;
323 }
324 return enumConstants.get(key);
325 }
326
327 @SuppressWarnings("all")
328 public static Object deserializeString(String value, Class type, boolean hex) {

Callers 1

deserializeStringMethod · 0.95

Calls 3

findBestMatchMethod · 0.95
getMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected