/** * Converts the objects in the given iterable in objects of the given target Class. * The objects are created by invoking its constructor passing to it the values taken * from the object to be converted using the given arguments. * Actually it handles also Maps, Arrays and Iterator by collecting their values. * Note that this method accepts an Object in order to be used in conjunction with the {@link Lambda#forEach(Iterable)}. * @param iterable The iterable containing the objects to be projected * @param targetClass The class in which the objects in the given iterable must be converted * @param arguments The arguments of the objects to be converted that will be used to create the objects of the target class * @return A list of map where each map is the result of the projection of an object in the iterable */ public static <T> List<T> project(Object iterable, Class<T> targetClass, Object... arguments) { return convert(iterable, new ConstructorArgumentConverter<Object, T>(targetClass, arguments)); }
public ConstructorArgumentConverter(Class<T> clazz, Object... arguments) { for (Constructor<?> c : clazz.getConstructors()) { if (isCompatible(c, arguments)) { this.constructor = (Constructor<T>)c; break; } } if (constructor == null) throw new IntrospectionException("Unable to find a constructor of " + clazz.getName() + " compatible with the given arguments"); if (arguments != null) for (Object argument : arguments) { argumentConverters.add(new ArgumentConverter<F, Object>(argument)); } }