@Test public void resourceToInstance() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { Object o = Common.toInstance("a", Resource.class); Assert.assertEquals(new Resource("a"), o); Assert.assertNotEquals(new Resource("b"), o); }
@SuppressWarnings("rawtypes") protected static Object toInstance(String value, Class<?> clazz) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (!clazz.isEnum()) { Constructor constructor = clazz.getConstructor(String.class); if (constructor != null) { return constructor.newInstance(value.trim()); } } else { Class<? extends Enum> eclazz = clazz.asSubclass(Enum.class); for (Enum e : eclazz.getEnumConstants()) { if (e.name().equalsIgnoreCase(value.trim())) { return e; } } } return null; }
Common { @SuppressWarnings("rawtypes") protected static Object toInstance(String value, Class<?> clazz) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (!clazz.isEnum()) { Constructor constructor = clazz.getConstructor(String.class); if (constructor != null) { return constructor.newInstance(value.trim()); } } else { Class<? extends Enum> eclazz = clazz.asSubclass(Enum.class); for (Enum e : eclazz.getEnumConstants()) { if (e.name().equalsIgnoreCase(value.trim())) { return e; } } } return null; } }
Common { @SuppressWarnings("rawtypes") protected static Object toInstance(String value, Class<?> clazz) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (!clazz.isEnum()) { Constructor constructor = clazz.getConstructor(String.class); if (constructor != null) { return constructor.newInstance(value.trim()); } } else { Class<? extends Enum> eclazz = clazz.asSubclass(Enum.class); for (Enum e : eclazz.getEnumConstants()) { if (e.name().equalsIgnoreCase(value.trim())) { return e; } } } return null; }  }
Common { @SuppressWarnings("rawtypes") protected static Object toInstance(String value, Class<?> clazz) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (!clazz.isEnum()) { Constructor constructor = clazz.getConstructor(String.class); if (constructor != null) { return constructor.newInstance(value.trim()); } } else { Class<? extends Enum> eclazz = clazz.asSubclass(Enum.class); for (Enum e : eclazz.getEnumConstants()) { if (e.name().equalsIgnoreCase(value.trim())) { return e; } } } return null; }  static Iterable<nu.xom.Element> iterable(final nu.xom.Elements elements); static Object fromString(String s); static String toString(Serializable o); }
Common { @SuppressWarnings("rawtypes") protected static Object toInstance(String value, Class<?> clazz) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (!clazz.isEnum()) { Constructor constructor = clazz.getConstructor(String.class); if (constructor != null) { return constructor.newInstance(value.trim()); } } else { Class<? extends Enum> eclazz = clazz.asSubclass(Enum.class); for (Enum e : eclazz.getEnumConstants()) { if (e.name().equalsIgnoreCase(value.trim())) { return e; } } } return null; }  static Iterable<nu.xom.Element> iterable(final nu.xom.Elements elements); static Object fromString(String s); static String toString(Serializable o); static BidiMap<String, Class<?>> classMap; }