From 67f20e0233abc67f7743554deb486049e8a88e1c Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 20 Nov 2021 18:24:52 +0800 Subject: Fix duplicate items with CC Tweaked --- .../me/shedaniel/rei/api/common/util/CollectionUtils.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'api/src') 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 List mapAndFilter(Iterable list, Predicate predicate, Function function) { + List 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 int sumInt(Iterable list, Function function) { int sum = 0; for (T t : list) { -- cgit