diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-11-20 18:24:52 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-11-20 18:24:52 +0800 |
| commit | a22f6fca95645893ebba1f79c4f643e165d0ed82 (patch) | |
| tree | 2a7eeea7b98d40e147552a5125cd603d1a1f1be1 /api/src/main/java/me | |
| parent | 8422dbb005ac16df728035d86c2c52acfcbd98af (diff) | |
| download | RoughlyEnoughItems-a22f6fca95645893ebba1f79c4f643e165d0ed82.tar.gz RoughlyEnoughItems-a22f6fca95645893ebba1f79c4f643e165d0ed82.tar.bz2 RoughlyEnoughItems-a22f6fca95645893ebba1f79c4f643e165d0ed82.zip | |
Fix duplicate items with CC Tweaked
Diffstat (limited to 'api/src/main/java/me')
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java | 13 |
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) { |
