TransformUtils { public static <T, E> Collection<E> map(Collection<T> items, Map<T> mapper) { Collection<E> result = new ArrayList<>(); for (T item : items) { result.add(mapper.map(item)); } return result; }  static Collection<T> filter(Collection<T> items, Predicate<T> predicate); static Collection<E> map(Collection<T> items, Map<T> mapper);  }
@Test public void testMap() throws Exception { Collection<Integer> data = Arrays.asList(2, 4, 6); Collection<Integer> newData = TransformUtils.map(data, new TransformUtils.Map<Integer>() { @Override public Integer map(Integer item) { return item / 2; } }); assertEquals(3, newData.size()); assertTrue(newData.contains(1)); assertTrue(newData.contains(2)); assertTrue(newData.contains(3)); }