@Test public void collectテスト() { final List<String> elements = Lists.gen("a", "b", "c", "d", "e"); final int[] datum = {0, elements.size()}; List<String> results = Lists.collect(elements, new CollectCall<String>() { public String collect(String element, int index, int total) { Assert.assertEquals(elements.get(index), element); Assert.assertEquals(datum[0]++, index); Assert.assertEquals(datum[1], total); return index % 2 == 0 ? element : null; } }); Assert.assertEquals(Lists.gen("a", "c", "e"), results); Assert.assertEquals(Lists.gen("a", "b", "c", "d", "e"), elements); }
public static <T> List<T> collect(List<T> elements, CollectCall<T> callback) { if (elements == null || callback == null || elements.size() == 0) return Collections.<T>emptyList(); int index = 0; int total = elements.size(); List<T> results = Reflects.make(elements.getClass()); for (T t : elements) { T result = callback.collect(t, index++, total); if (result != null) results.add(result); } return results; }
Lists { public static <T> List<T> collect(List<T> elements, CollectCall<T> callback) { if (elements == null || callback == null || elements.size() == 0) return Collections.<T>emptyList(); int index = 0; int total = elements.size(); List<T> results = Reflects.make(elements.getClass()); for (T t : elements) { T result = callback.collect(t, index++, total); if (result != null) results.add(result); } return results; } }
Lists { public static <T> List<T> collect(List<T> elements, CollectCall<T> callback) { if (elements == null || callback == null || elements.size() == 0) return Collections.<T>emptyList(); int index = 0; int total = elements.size(); List<T> results = Reflects.make(elements.getClass()); for (T t : elements) { T result = callback.collect(t, index++, total); if (result != null) results.add(result); } return results; } private  Lists(); }
Lists { public static <T> List<T> collect(List<T> elements, CollectCall<T> callback) { if (elements == null || callback == null || elements.size() == 0) return Collections.<T>emptyList(); int index = 0; int total = elements.size(); List<T> results = Reflects.make(elements.getClass()); for (T t : elements) { T result = callback.collect(t, index++, total); if (result != null) results.add(result); } return results; } private  Lists(); static List<T> gen(T... elements); static List<T> gen(int size, GenCall<T> generator); static U gen(int size, Class<U> container, GenCall<T> generator); static List<T> each(List<T> elements, EachCall<T> callback); static List<T> collect(List<T> elements, CollectCall<T> callback); static Map<String, List<T>> group(List<T> elements, GroupCall<T> callback); static boolean isEmpty(List<T> suspect); static PartialList<T> emptyPartialList(); }
Lists { public static <T> List<T> collect(List<T> elements, CollectCall<T> callback) { if (elements == null || callback == null || elements.size() == 0) return Collections.<T>emptyList(); int index = 0; int total = elements.size(); List<T> results = Reflects.make(elements.getClass()); for (T t : elements) { T result = callback.collect(t, index++, total); if (result != null) results.add(result); } return results; } private  Lists(); static List<T> gen(T... elements); static List<T> gen(int size, GenCall<T> generator); static U gen(int size, Class<U> container, GenCall<T> generator); static List<T> each(List<T> elements, EachCall<T> callback); static List<T> collect(List<T> elements, CollectCall<T> callback); static Map<String, List<T>> group(List<T> elements, GroupCall<T> callback); static boolean isEmpty(List<T> suspect); static PartialList<T> emptyPartialList(); @SuppressWarnings("rawtypes")
    static final PartialList EMPTY_PARTIAL_LIST; }