From b7246fa0016888fd52c45f9c77df46f9d791e326 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 15 Nov 2019 20:09:15 +0800 Subject: Using more of the API instead of the Impl --- src/main/java/me/shedaniel/rei/utils/CollectionUtils.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/main/java/me/shedaniel/rei/utils/CollectionUtils.java') diff --git a/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java b/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java index d2b7eb92a..20e20d162 100644 --- a/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java +++ b/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java @@ -47,14 +47,13 @@ public class CollectionUtils { } public static final List filter(List list, Predicate predicate) { - List l = null; + List l = new LinkedList<>(); for (T t : list) { if (predicate.test(t)) { - if (l == null) l = new LinkedList<>(); l.add(t); } } - return l == null ? Collections.emptyList() : l; + return l; } public static final List map(List list, Function function) { @@ -158,7 +157,7 @@ public class CollectionUtils { public static final int sumInt(List list) { int sum = 0; - for (Integer t : list) { + for (int t : list) { sum += t; } return sum; @@ -174,7 +173,7 @@ public class CollectionUtils { public static final double sumDouble(List list) { double sum = 0; - for (Double t : list) { + for (double t : list) { sum += t; } return sum; -- cgit