import java.util.ArrayList; import java.util.Collection; public class Enumerable { public static Collection map(Collection c, Filter f) { ArrayList result = new ArrayList(); for (T e : c) { result.add(f.apply(e)); } return result; } public static Collection map(T[] c, Filter f) { ArrayList result = new ArrayList(); for (T e : c) { result.add(f.apply(e)); } return result; } public static Collection select(Collection c, Predicate p) { ArrayList result = new ArrayList(); for (T e : c) { if (p.apply(e)) { result.add(e); } } return result; } public static Collection select(T[] c, Predicate p) { ArrayList result = new ArrayList(); for (T e : c) { if (p.apply(e)) { result.add(e); } } return result; } public static Collection reject(Collection c, Predicate p) { ArrayList result = new ArrayList(); for (T e : c) { if (! p.apply(e)) { result.add(e); } } return result; } public static Collection reject(T[] c, Predicate p) { ArrayList result = new ArrayList(); for (T e : c) { if (! p.apply(e)) { result.add(e); } } return result; } public static boolean all(Collection c, Predicate p) { for (T e : c) { if (! p.apply(e)) { return false; } } return true; } public static boolean all(T[] c, Predicate p) { for (T e : c) { if (! p.apply(e)) { return false; } } return true; } public static boolean any(Collection c, Predicate p) { for (T e : c) { if (p.apply(e)) { return true; } } return false; } public static boolean any(T[] c, Predicate p) { for (T e : c) { if (p.apply(e)) { return true; } } return false; } }