/* * Copyright (c) 2007 Mockito contributors * This program is made available under the terms of the MIT License. */ package org.mockito.internal.util.collections; import java.util.Collection; import java.util.LinkedList; /** * Basic list/collection operators. * We know that there are existing libraries that implement those use cases neatly. * However, we want to keep Mockito dependencies minimal. * In Java8 we should be able to get rid of this class. */ public class ListUtil { public static LinkedList filter(Collection collection, Filter filter) { LinkedList filtered = new LinkedList(); for (T t : collection) { if (!filter.isOut(t)) { filtered.add(t); } } return filtered; } public static LinkedList convert(Collection collection, Converter converter) { LinkedList converted = new LinkedList(); for (From f: collection) { converted.add(converter.convert(f)); } return converted; } public interface Filter { boolean isOut(T object); } public interface Converter { To convert(From from); } }