@Test public void testMap() throws Exception { List<String> mappedList = CollectionHelper.map(testCollection, new Mapper<Integer, String>() { @Override public String map(Integer object) { return String.format(Locale.US, "i%d", object); } }); assertThat(mappedList, is(Arrays.asList("i1", "i4", "i2", "i7", "i8", "i0", "i5"))); }
public static <TSource, TResult> List<TResult> map(Collection<TSource> items, Mapper<TSource, TResult> mapper) { if (isEmpty(items)) { return new ArrayList<>(); } List<TResult> result = new ArrayList<>(items.size()); for (TSource item : items) { TResult mappedItem = mapper.map(item); result.add(mappedItem); } return result; }
CollectionHelper { public static <TSource, TResult> List<TResult> map(Collection<TSource> items, Mapper<TSource, TResult> mapper) { if (isEmpty(items)) { return new ArrayList<>(); } List<TResult> result = new ArrayList<>(items.size()); for (TSource item : items) { TResult mappedItem = mapper.map(item); result.add(mappedItem); } return result; } }
CollectionHelper { public static <TSource, TResult> List<TResult> map(Collection<TSource> items, Mapper<TSource, TResult> mapper) { if (isEmpty(items)) { return new ArrayList<>(); } List<TResult> result = new ArrayList<>(items.size()); for (TSource item : items) { TResult mappedItem = mapper.map(item); result.add(mappedItem); } return result; } private  CollectionHelper(); }
CollectionHelper { public static <TSource, TResult> List<TResult> map(Collection<TSource> items, Mapper<TSource, TResult> mapper) { if (isEmpty(items)) { return new ArrayList<>(); } List<TResult> result = new ArrayList<>(items.size()); for (TSource item : items) { TResult mappedItem = mapper.map(item); result.add(mappedItem); } return result; } private  CollectionHelper(); static List<T> filter(Collection<T> items, Predicate<T> predicate); static T first(Collection<T> items, Predicate<T> predicate); static T firstOrNull(Collection<T> items, Predicate<T> predicate); static int firstIndexOf(Collection<T> items, Predicate<T> predicate); static boolean any(Collection<T> items, Predicate<T> predicate); static boolean all(Collection<T> items, Predicate<T> predicate); static boolean isEmpty(Collection items); static T single(Collection<T> items, Predicate<T> predicate); static T singleOrNull(Collection<T> items, Predicate<T> predicate); static int singleIndexOf(Collection<T> items, Predicate<T> predicate); static int count(Collection<T> items, Predicate<T> predicate); static List<TResult> map(Collection<TSource> items, Mapper<TSource, TResult> mapper); }
CollectionHelper { public static <TSource, TResult> List<TResult> map(Collection<TSource> items, Mapper<TSource, TResult> mapper) { if (isEmpty(items)) { return new ArrayList<>(); } List<TResult> result = new ArrayList<>(items.size()); for (TSource item : items) { TResult mappedItem = mapper.map(item); result.add(mappedItem); } return result; } private  CollectionHelper(); static List<T> filter(Collection<T> items, Predicate<T> predicate); static T first(Collection<T> items, Predicate<T> predicate); static T firstOrNull(Collection<T> items, Predicate<T> predicate); static int firstIndexOf(Collection<T> items, Predicate<T> predicate); static boolean any(Collection<T> items, Predicate<T> predicate); static boolean all(Collection<T> items, Predicate<T> predicate); static boolean isEmpty(Collection items); static T single(Collection<T> items, Predicate<T> predicate); static T singleOrNull(Collection<T> items, Predicate<T> predicate); static int singleIndexOf(Collection<T> items, Predicate<T> predicate); static int count(Collection<T> items, Predicate<T> predicate); static List<TResult> map(Collection<TSource> items, Mapper<TSource, TResult> mapper); static final int NOT_FOUND_INDEX; }