### Question:
TypeConverter { public static String findConstByValue(Class<?> type, String value, Class<?> constType) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { if (type.isEnum()) { Method[] methods = type.getDeclaredMethods(); for (Method method : methods) { if("getEnumValue".equals(method.getName())) { if (method.getParameterTypes().length == 1) { Matcher matcher = CAST_PATTERN.matcher(value); if(matcher.find()) { value = matcher.group("value"); } Object objArg = convertToObject(method.getParameterTypes()[0], value); Object objVal = method.invoke(null, objArg); return type.getCanonicalName() + "." + objVal; } } } for (Object constant : type.getEnumConstants()) { if (constant.toString().equals(value)) { return type.getCanonicalName() + "." + constant; } } return null; } Field[] constants = type.getDeclaredFields(); for (Field constant : constants) { if ((constType == null || constant.getType().equals(constType)) && ((constant.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC) && ((constant.getModifiers() & Modifier.STATIC) == Modifier.STATIC) && ((constant.getModifiers() & Modifier.FINAL) == Modifier.FINAL)) { try { Object objArg = convertToObject(constant.getType(), value); Object cvalue = constant.get(null); if (objArg.equals(cvalue)) { return type.getCanonicalName()+"."+constant.getName(); } } catch (Exception e) { logger.warn("Value '{}' can not be converted to type {}", value, constant.getType()); } } } return null; } private  TypeConverter(); static String findConstant(Class<?> type, String constantName); static String findConstant(Class<?> type, String value, AtomicReference<Class<?>> constType); static Object findConstantValue(Class<?> type, String name, Class<?> constType); static boolean convert(Class<?> type, AtomicReference<String> value); static String convert(Class<?> type, String value); static String findConstantByValue(Class<?> type, String value); static String findConstByValue(Class<?> type, String value, Class<?> constType); static Object convertToObject(Class<?> type, String value); static Constructor<?> findConstructor(Class<?> type, Class<?> parameterType); static Constructor<?> inferConstructor(Class<?> type);  }### Answer:
@Test public void testFindConstByValue() throws Exception { assertEquals("com.exactpro.sf.messages.testaml.components.SideITCH.BUY", TypeConverter.findConstantByValue(SideITCH.class, "66")); assertEquals("com.exactpro.sf.messages.testaml.components.SideITCH.SELL", TypeConverter.findConstantByValue(SideITCH.class, "83")); }