aboutsummaryrefslogtreecommitdiff
path: root/api/src
diff options
context:
space:
mode:
Diffstat (limited to 'api/src')
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java
index 0d20cf7f9..946d9336f 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java
@@ -265,6 +265,19 @@ public class CollectionUtils {
return l == null ? Collections.emptyList() : l;
}
+ public static <T, R> List<R> mapAndFilter(Iterable<T> list, Predicate<R> predicate, Function<T, R> function) {
+ List<R> l = null;
+ for (T t : list) {
+ R r = function.apply(t);
+ if (predicate.test(r)) {
+ if (l == null)
+ l = Lists.newArrayList();
+ l.add(r);
+ }
+ }
+ return l == null ? Collections.emptyList() : l;
+ }
+
public static <T> int sumInt(Iterable<T> list, Function<T, Integer> function) {
int sum = 0;
for (T t : list) {