/** * Sums the items in the given iterable of Numbers or the iterable itself if it actually is already a single number. * 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 of numbers to be summed * @return The sum of all the Number in the given iterable or the iterable itself if it actually is already a single number * @throws IllegalArgumentException if the iterable is not neither an Iterable nor a Number */ public static Number sum(Object iterable) { return typedSum(iterable, Double.class); }
/** * Sums the property values of the items in the given iterable defined by the given argument. * 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 of items containing the property of which the values have to be summed. * @param argument An argument defined using the {@link Lambda#on(Class)} method * @return The sum of the property values extracted from all the items in the given iterable * @throws IllegalArgumentException if the iterable is not an Iterable */ public static <T> T sum(Object iterable, T argument) { return (T)typedSum(convertIterator(iterable, new ArgumentConverter<Object, T>(argument)), argument.getClass()); }