@Test public void testInvokeFirst() throws Exception { ConstructorTestClass ctc = GobblinConstructorUtils.invokeFirstConstructor(ConstructorTestClass.class, ImmutableList.<Object>of(Integer.valueOf(3), new Properties()), ImmutableList.<Object>of(Integer.valueOf(3), "test1")); Assert.assertNotNull(ctc.id); Assert.assertNotNull(ctc.props); Assert.assertEquals(ctc.id, Integer.valueOf(3)); Assert.assertNull(ctc.str); ctc = GobblinConstructorUtils .invokeFirstConstructor(ConstructorTestClass.class, ImmutableList.<Object>of(Integer.valueOf(3), "test1"), ImmutableList.<Object>of(Integer.valueOf(3), new Properties())); Assert.assertNotNull(ctc.id); Assert.assertNotNull(ctc.str); Assert.assertEquals(ctc.id, Integer.valueOf(3)); Assert.assertEquals(ctc.str, "test1"); Assert.assertNull(ctc.props); }
@SafeVarargs public static <T> T invokeFirstConstructor(Class<T> cls, List<Object>... constructorArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { for (List<Object> args : constructorArgs) { Class<?>[] parameterTypes = new Class[args.size()]; for (int i = 0; i < args.size(); i++) { parameterTypes[i] = args.get(i).getClass(); } if (ConstructorUtils.getMatchingAccessibleConstructor(cls, parameterTypes) != null) { return ConstructorUtils.invokeConstructor(cls, args.toArray(new Object[args.size()])); } } throw new NoSuchMethodException("No accessible constructor found"); }
GobblinConstructorUtils { @SafeVarargs public static <T> T invokeFirstConstructor(Class<T> cls, List<Object>... constructorArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { for (List<Object> args : constructorArgs) { Class<?>[] parameterTypes = new Class[args.size()]; for (int i = 0; i < args.size(); i++) { parameterTypes[i] = args.get(i).getClass(); } if (ConstructorUtils.getMatchingAccessibleConstructor(cls, parameterTypes) != null) { return ConstructorUtils.invokeConstructor(cls, args.toArray(new Object[args.size()])); } } throw new NoSuchMethodException("No accessible constructor found"); } }
GobblinConstructorUtils { @SafeVarargs public static <T> T invokeFirstConstructor(Class<T> cls, List<Object>... constructorArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { for (List<Object> args : constructorArgs) { Class<?>[] parameterTypes = new Class[args.size()]; for (int i = 0; i < args.size(); i++) { parameterTypes[i] = args.get(i).getClass(); } if (ConstructorUtils.getMatchingAccessibleConstructor(cls, parameterTypes) != null) { return ConstructorUtils.invokeConstructor(cls, args.toArray(new Object[args.size()])); } } throw new NoSuchMethodException("No accessible constructor found"); }  }
GobblinConstructorUtils { @SafeVarargs public static <T> T invokeFirstConstructor(Class<T> cls, List<Object>... constructorArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { for (List<Object> args : constructorArgs) { Class<?>[] parameterTypes = new Class[args.size()]; for (int i = 0; i < args.size(); i++) { parameterTypes[i] = args.get(i).getClass(); } if (ConstructorUtils.getMatchingAccessibleConstructor(cls, parameterTypes) != null) { return ConstructorUtils.invokeConstructor(cls, args.toArray(new Object[args.size()])); } } throw new NoSuchMethodException("No accessible constructor found"); }  @SafeVarargs static T invokeFirstConstructor(Class<T> cls, List<Object>... constructorArgs); static T invokeLongestConstructor(Class<T> cls, Object... args); @SuppressWarnings("unchecked") static T invokeConstructor(final Class<T> superType, final String clsName, Object... args); }
GobblinConstructorUtils { @SafeVarargs public static <T> T invokeFirstConstructor(Class<T> cls, List<Object>... constructorArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { for (List<Object> args : constructorArgs) { Class<?>[] parameterTypes = new Class[args.size()]; for (int i = 0; i < args.size(); i++) { parameterTypes[i] = args.get(i).getClass(); } if (ConstructorUtils.getMatchingAccessibleConstructor(cls, parameterTypes) != null) { return ConstructorUtils.invokeConstructor(cls, args.toArray(new Object[args.size()])); } } throw new NoSuchMethodException("No accessible constructor found"); }  @SafeVarargs static T invokeFirstConstructor(Class<T> cls, List<Object>... constructorArgs); static T invokeLongestConstructor(Class<T> cls, Object... args); @SuppressWarnings("unchecked") static T invokeConstructor(final Class<T> superType, final String clsName, Object... args);  }