@Test public void testAsItself() { assertEquals(MERGE, as(MERGE, Should.class)); }
@SneakyThrows @SuppressWarnings({"PMD.ShortMethodName", "rawtypes"}) public static <T> T as(Object element, Class<T> objectClass) { Class<?> elementType = element.getClass(); if (is(elementType, objectClass)) { return (T) element; } for (ElementParser elementParser : ELEMENT_PARSERS) { if (is(elementType, elementParser.elementType())) { return (T) elementParser.as(element, objectClass); } } if (objectClass.isEnum()) { return (T) Enum.valueOf((Class<Enum>) objectClass, (String) element); } throw Query.Exceptions.invalidObjectType(element, objectClass); }
Parser { @SneakyThrows @SuppressWarnings({"PMD.ShortMethodName", "rawtypes"}) public static <T> T as(Object element, Class<T> objectClass) { Class<?> elementType = element.getClass(); if (is(elementType, objectClass)) { return (T) element; } for (ElementParser elementParser : ELEMENT_PARSERS) { if (is(elementType, elementParser.elementType())) { return (T) elementParser.as(element, objectClass); } } if (objectClass.isEnum()) { return (T) Enum.valueOf((Class<Enum>) objectClass, (String) element); } throw Query.Exceptions.invalidObjectType(element, objectClass); } }
Parser { @SneakyThrows @SuppressWarnings({"PMD.ShortMethodName", "rawtypes"}) public static <T> T as(Object element, Class<T> objectClass) { Class<?> elementType = element.getClass(); if (is(elementType, objectClass)) { return (T) element; } for (ElementParser elementParser : ELEMENT_PARSERS) { if (is(elementType, elementParser.elementType())) { return (T) elementParser.as(element, objectClass); } } if (objectClass.isEnum()) { return (T) Enum.valueOf((Class<Enum>) objectClass, (String) element); } throw Query.Exceptions.invalidObjectType(element, objectClass); } private  Parser(); }
Parser { @SneakyThrows @SuppressWarnings({"PMD.ShortMethodName", "rawtypes"}) public static <T> T as(Object element, Class<T> objectClass) { Class<?> elementType = element.getClass(); if (is(elementType, objectClass)) { return (T) element; } for (ElementParser elementParser : ELEMENT_PARSERS) { if (is(elementType, elementParser.elementType())) { return (T) elementParser.as(element, objectClass); } } if (objectClass.isEnum()) { return (T) Enum.valueOf((Class<Enum>) objectClass, (String) element); } throw Query.Exceptions.invalidObjectType(element, objectClass); } private  Parser(); static void registerElementParser(ElementParser<?> elementParser); static boolean isPropertyValue(Field field); @SneakyThrows @SuppressWarnings({"PMD.ShortMethodName", "rawtypes"}) static T as(Object element, Class<T> objectClass); }
Parser { @SneakyThrows @SuppressWarnings({"PMD.ShortMethodName", "rawtypes"}) public static <T> T as(Object element, Class<T> objectClass) { Class<?> elementType = element.getClass(); if (is(elementType, objectClass)) { return (T) element; } for (ElementParser elementParser : ELEMENT_PARSERS) { if (is(elementType, elementParser.elementType())) { return (T) elementParser.as(element, objectClass); } } if (objectClass.isEnum()) { return (T) Enum.valueOf((Class<Enum>) objectClass, (String) element); } throw Query.Exceptions.invalidObjectType(element, objectClass); } private  Parser(); static void registerElementParser(ElementParser<?> elementParser); static boolean isPropertyValue(Field field); @SneakyThrows @SuppressWarnings({"PMD.ShortMethodName", "rawtypes"}) static T as(Object element, Class<T> objectClass);  }