/** * Joins all the object in the given iterable by concatenating all their String representation. * It invokes toString() an all the objects and concatening them using the default separator ", ". * 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 joined * @return The concatenation of the String representation of all the objects in the given iterable or an empty String if the iterable is null or empty */ public static String join(Object iterable) { return join(iterable, ", "); }
/** * Finds the maximum item 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 objects on which the maximum should be found * @param argument An argument defined using the {@link Lambda#on(Class)} method * @return The maximum of all the Object in the given iterable * @throws IllegalArgumentException if the iterable is not an Iterable */ public static <T> T max(Object iterable, T argument) { return (T)aggregate(iterable, MAX, argument); }
/** * Filters away all the duplicated items in the given iterable. * @param iterable The iterable of objects to be filtered * @return A Collection with the same items of the given iterable but containing no duplicate elements */ public static <T> Collection<T> selectDistinct(Iterable<T> iterable) { return selectDistinct(iterable, (Comparator<T>) null); }
private List<File> convertToFiles(List<String> fileList) { return convert(fileList, new Converter<String, File>() { @Override public File convert(String from) { return new File(from); } }); }
/** * Counts the number of occurrencies of the argument's value in the objects of the given iterable * 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 objects' arguments to be counted * @param argument An argument defined using the {@link Lambda#on(Class)} method * @return A map having as values the number of occurrencies of the corresponding object's argument in the given iterable */ public static <A> Map<A, Integer> count(Object iterable, A argument) { return count(extract(iterable, argument)); }
/** * Returns true if the given iterable contains at least an item that matches the given hamcrest Matcher * 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 objects to be filtered * @param matcher The hamcrest Matcher used to filter the given iterable * @return True if the given iterable contains at least an item that matches the given hamcrest Matcher false otherwise */ public static boolean exists(Object iterable, Matcher<?> matcher) { return selectFirst(iterable, matcher) != null; }
/** * Sorts all the items in the given iterable on the respective values of 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 objects to be sorted * @param argument An argument defined using the {@link Lambda#on(Class)} method * @return A List with the same items of the given iterable sorted on the respective value of the given argument */ public static <T> List<T> sort(Object iterable, Object argument) { return sort(iterable, argument, 0); }
/** * Filters all the objects in the given iterable that match the given hamcrest Matcher * @param matcher The hamcrest Matcher used to filter the given iterable * @param iterable The iterable of objects to be filtered * @return A sublist of the given iterable containing all the objects that match the given hamcrest Matcher */ public static <T> List<T> filter(Matcher<?> matcher, Iterable<T> iterable) { return select(iterable, matcher); }
/** * Returns a proxy of the class of the first object in this iterable that when invoked with a method returning a number * returns the sum of the numbers resulting from the invocation of the same method on each item in this iterable * @return A proxy of the class of the first object in this iterable representing a sum lambda function * @throws IllegalArgumentException if this iterable is null or empty */ public T sumFrom() { return Lambda.sumFrom(innerIterable); }
/** * Returns a proxy of the class of the first object in this iterable that when invoked with a method returning a String * returns a comma separated string that is the concatenation of the Strings resulting from the invocation * of the same method on each item in this iterable * @return A proxy of the class of the first object in this iterable representing a join lambda function * @throws IllegalArgumentException if this iterable is null or empty */ public T joinFrom() { return Lambda.joinFrom(innerIterable); }
/** * 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); }
/** * Calculates the average of 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 average 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 avg(Object iterable) { return typedAvg(iterable, Double.class); }
/** * Returns a proxy of the class of the first object in this iterable that when invoked with a method returning a Comparable * returns the minimimum of the Caomparables resulting from the invocation of the same method on each item in this iterable * @return A proxy of the class of the first object in this iterable representing a sum lambda function * @throws IllegalArgumentException if this iterable is null or empty */ public T minFrom() { return Lambda.minFrom(innerIterable); }
/** * Filters all the objects in the given array that match the given hamcrest Matcher * @param matcher The hamcrest Matcher used to filter the given array * @param array The array of objects to be filtered * @return A sublist of the given array containing all the objects that match the given hamcrest Matcher */ public static <T> List<T> filter(Matcher<?> matcher, T... array) { return select(array, matcher); }
/** * Finds the maximum item in the given iterable. * 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 objects on which the maximum should be found * @return The maximum of all the Object in the given iterable * @throws IllegalArgumentException if the iterable is not an Iterable */ public static <T> T max(Object iterable) { return (T) aggregate(iterable, MAX); }
/** * Filters away all the duplicated items in the given iterable. * 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 objects to be filtered * @return A Collection with the same items of the given iterable but containing no duplicate elements */ public static <T> Collection<T> selectDistinct(Object iterable) { return selectDistinct(iterable, (Comparator<T>) null); }
/** * Returns a proxy of the class of the first object in this iterable that when invoked with a method returning a String * returns a string separated with the given separator that is the concatenation of the Strings resulting from the invocation * of the same method on each item in this iterable * @param separator The String used to separe the Strings produced by this proxy * @return A proxy of the class of the first object in this iterable representing a join lambda function * @throws IllegalArgumentException if this iterable is null or empty */ public T joinFrom(String separator) { return Lambda.joinFrom(innerIterable, separator); }
/** * Finds the minimum item 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 objects on which the minimum should be found * @param argument An argument defined using the {@link Lambda#on(Class)} method * @return The minimum of all the Object in the given iterable * @throws IllegalArgumentException if the iterable is not an Iterable */ public static <T> T min(Object iterable, T argument) { return (T)aggregate(iterable, MIN, argument); }
/** * Finds the minimum item in the given iterable. * 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 minimum of all the Object in the given iterable * @throws IllegalArgumentException if the iterable is not an Iterable */ public static <T> T min(Object iterable) { return (T) aggregate(iterable, MIN); }