-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
ListUtil.java
51 lines (44 loc) · 1.36 KB
/
ListUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* 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.
*/
@Deprecated
public final class ListUtil {
@Deprecated
public static <T> LinkedList<T> filter(Collection<T> collection, Filter<T> filter) {
LinkedList<T> filtered = new LinkedList<T>();
for (T t : collection) {
if (!filter.isOut(t)) {
filtered.add(t);
}
}
return filtered;
}
@Deprecated
public static <FromT, To> LinkedList<To> convert(
Collection<FromT> collection, Converter<FromT, To> converter) {
LinkedList<To> converted = new LinkedList<To>();
for (FromT f : collection) {
converted.add(converter.convert(f));
}
return converted;
}
@Deprecated
public interface Filter<T> {
boolean isOut(T object);
}
@Deprecated
public interface Converter<FromT, To> {
To convert(FromT from);
}
@Deprecated
private ListUtil() {}
}