@Test public void eachテスト() { final String[] elements = {"a", "b", "c", "d", "e"}; final int[] datum = {0, elements.length}; Arrays.each(elements, new EachCall<String>() { public void each(String element, int index, int total) { Assert.assertEquals(elements[index], element); Assert.assertEquals(datum[0]++, index); Assert.assertEquals(datum[1], total); } }); }
public static <T> T[] each(T[] elements, EachCall<T> callback) { if (elements == null || callback == null || elements.length == 0) return elements; int index = 0; int total = elements.length; for (T t : elements) { callback.each(t, index++, total); } return elements; }
Arrays { public static <T> T[] each(T[] elements, EachCall<T> callback) { if (elements == null || callback == null || elements.length == 0) return elements; int index = 0; int total = elements.length; for (T t : elements) { callback.each(t, index++, total); } return elements; } }
Arrays { public static <T> T[] each(T[] elements, EachCall<T> callback) { if (elements == null || callback == null || elements.length == 0) return elements; int index = 0; int total = elements.length; for (T t : elements) { callback.each(t, index++, total); } return elements; } private  Arrays(); }
Arrays { public static <T> T[] each(T[] elements, EachCall<T> callback) { if (elements == null || callback == null || elements.length == 0) return elements; int index = 0; int total = elements.length; for (T t : elements) { callback.each(t, index++, total); } return elements; } private  Arrays(); static T[] gen(T... elements); @SuppressWarnings("unchecked") static T[] gen(int size, GenCall<T> generator); static int contain(T[] t, T suspect); static Iterator<T> iterator(T... elements); @SuppressWarnings("unchecked") static T[] merge(final T[] former, final T... latter); static T[] each(T[] elements, EachCall<T> callback); @SuppressWarnings("unchecked") static T[] collect(T[] elements, CollectCall<T> callback); @SuppressWarnings("unchecked") static Map<String, T[]> group(T[] elements, GroupCall<T> callback); static boolean isEmpty(T[] suspect); static boolean isNotEmpty(T[] suspect); static T[] slice(T[] slicee, int start); @SuppressWarnings("unchecked") static T[] slice(T[] slicee, int start, int length); }
Arrays { public static <T> T[] each(T[] elements, EachCall<T> callback) { if (elements == null || callback == null || elements.length == 0) return elements; int index = 0; int total = elements.length; for (T t : elements) { callback.each(t, index++, total); } return elements; } private  Arrays(); static T[] gen(T... elements); @SuppressWarnings("unchecked") static T[] gen(int size, GenCall<T> generator); static int contain(T[] t, T suspect); static Iterator<T> iterator(T... elements); @SuppressWarnings("unchecked") static T[] merge(final T[] former, final T... latter); static T[] each(T[] elements, EachCall<T> callback); @SuppressWarnings("unchecked") static T[] collect(T[] elements, CollectCall<T> callback); @SuppressWarnings("unchecked") static Map<String, T[]> group(T[] elements, GroupCall<T> callback); static boolean isEmpty(T[] suspect); static boolean isNotEmpty(T[] suspect); static T[] slice(T[] slicee, int start); @SuppressWarnings("unchecked") static T[] slice(T[] slicee, int start, int length);  }