diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-01-02 14:31:16 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-01-02 14:31:16 +0800 |
| commit | 5e2eccadbd91171c01cdb209d1338bcfb7786b1c (patch) | |
| tree | 6c7387de5baea8b335e8abe58651018f77ad2d41 /src/main/java/me/shedaniel/rei/utils/CollectionUtils.java | |
| parent | e8714fe8fc1dcaec7ad299c63e2b657870c8fb40 (diff) | |
| download | RoughlyEnoughItems-5e2eccadbd91171c01cdb209d1338bcfb7786b1c.tar.gz RoughlyEnoughItems-5e2eccadbd91171c01cdb209d1338bcfb7786b1c.tar.bz2 RoughlyEnoughItems-5e2eccadbd91171c01cdb209d1338bcfb7786b1c.zip | |
3.3
Fix #58
Close #134
Close #158
Fix #227
Diffstat (limited to 'src/main/java/me/shedaniel/rei/utils/CollectionUtils.java')
| -rw-r--r-- | src/main/java/me/shedaniel/rei/utils/CollectionUtils.java | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java b/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java index 6460e119a..4c2dd7a04 100644 --- a/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java +++ b/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java @@ -14,39 +14,39 @@ import java.util.function.Predicate; @Internal public class CollectionUtils { - public static final <T> T findFirstOrNullEquals(List<T> list, T obj) { + public static <T> T findFirstOrNullEquals(List<T> list, T obj) { for (T t : list) { if (t.equals(obj)) return t; } return null; } - - public static final <T> T findFirstOrNull(List<T> list, Predicate<T> predicate) { + + public static <T> T findFirstOrNull(List<T> list, Predicate<T> predicate) { for (T t : list) { if (predicate.test(t)) return t; } return null; } - - public static final <T> boolean anyMatch(List<T> list, Predicate<T> predicate) { + + public static <T> boolean anyMatch(List<T> list, Predicate<T> predicate) { for (T t : list) { if (predicate.test(t)) return true; } return false; } - - public static final boolean anyMatchEqualsAll(List<EntryStack> list, EntryStack stack) { + + public static boolean anyMatchEqualsAll(List<EntryStack> list, EntryStack stack) { for (EntryStack t : list) { if (t.equalsAll(stack)) return true; } return false; } - - public static final <T> List<T> filter(List<T> list, Predicate<T> predicate) { + + public static <T> List<T> filter(List<T> list, Predicate<T> predicate) { List<T> l = new LinkedList<>(); for (T t : list) { if (predicate.test(t)) { @@ -55,88 +55,88 @@ public class CollectionUtils { } return l; } - - public static final <T, R> List<R> map(List<T> list, Function<T, R> function) { + + public static <T, R> List<R> map(List<T> list, Function<T, R> function) { List<R> l = new LinkedList<>(); for (T t : list) { l.add(function.apply(t)); } return l; } - - public static final <T, R> List<R> map(T[] list, Function<T, R> function) { + + public static <T, R> List<R> map(T[] list, Function<T, R> function) { List<R> l = new LinkedList<>(); for (T t : list) { l.add(function.apply(t)); } return l; } - - public static final <T, R> Optional<R> mapAndMax(List<T> list, Function<T, R> function, Comparator<R> comparator) { + + public static <T, R> Optional<R> mapAndMax(List<T> list, Function<T, R> function, Comparator<R> comparator) { if (list.isEmpty()) return Optional.empty(); List<R> copyOf = CollectionUtils.map(list, function); copyOf.sort(comparator); return Optional.ofNullable(copyOf.get(copyOf.size() - 1)); } - - public static final <T, R> Optional<R> mapAndMax(T[] list, Function<T, R> function, Comparator<R> comparator) { + + public static <T, R> Optional<R> mapAndMax(T[] list, Function<T, R> function, Comparator<R> comparator) { if (list.length <= 0) return Optional.empty(); List<R> copyOf = CollectionUtils.map(list, function); copyOf.sort(comparator); return Optional.ofNullable(copyOf.get(copyOf.size() - 1)); } - - public static final <T> Optional<T> max(List<T> list, Comparator<T> comparator) { + + public static <T> Optional<T> max(List<T> list, Comparator<T> comparator) { if (list.isEmpty()) return Optional.empty(); ArrayList<T> ts = new ArrayList<>(list); ts.sort(comparator); return Optional.ofNullable(ts.get(ts.size() - 1)); } - - public static final <T> Optional<T> max(T[] list, Comparator<T> comparator) { + + public static <T> Optional<T> max(T[] list, Comparator<T> comparator) { if (list.length <= 0) return Optional.empty(); T[] copyOf = list.clone(); Arrays.sort(copyOf, comparator); return Optional.ofNullable(copyOf[copyOf.length - 1]); } - - public static final String joinToString(List<String> list, String separator) { + + public static String joinToString(List<String> list, String separator) { StringJoiner joiner = new StringJoiner(separator); for (String t : list) { joiner.add(t); } return joiner.toString(); } - - public static final String joinToString(String[] list, String separator) { + + public static String joinToString(String[] list, String separator) { StringJoiner joiner = new StringJoiner(separator); for (String t : list) { joiner.add(t); } return joiner.toString(); } - - public static final <T> String mapAndJoinToString(List<T> list, Function<T, String> function, String separator) { + + public static <T> String mapAndJoinToString(List<T> list, Function<T, String> function, String separator) { StringJoiner joiner = new StringJoiner(separator); for (T t : list) { joiner.add(function.apply(t)); } return joiner.toString(); } - - public static final <T> String mapAndJoinToString(T[] list, Function<T, String> function, String separator) { + + public static <T> String mapAndJoinToString(T[] list, Function<T, String> function, String separator) { StringJoiner joiner = new StringJoiner(separator); for (T t : list) { joiner.add(function.apply(t)); } return joiner.toString(); } - - public static final <T, R> List<R> filterAndMap(List<T> list, Predicate<T> predicate, Function<T, R> function) { + + public static <T, R> List<R> filterAndMap(List<T> list, Predicate<T> predicate, Function<T, R> function) { List<R> l = null; for (T t : list) { if (predicate.test(t)) { @@ -147,32 +147,32 @@ public class CollectionUtils { } return l == null ? Collections.emptyList() : l; } - - public static final <T> int sumInt(List<T> list, Function<T, Integer> function) { + + public static <T> int sumInt(List<T> list, Function<T, Integer> function) { int sum = 0; for (T t : list) { sum += function.apply(t); } return sum; } - - public static final <T> int sumInt(List<Integer> list) { + + public static <T> int sumInt(List<Integer> list) { int sum = 0; for (int t : list) { sum += t; } return sum; } - - public static final <T> double sumDouble(List<T> list, Function<T, Double> function) { + + public static <T> double sumDouble(List<T> list, Function<T, Double> function) { double sum = 0; for (T t : list) { sum += function.apply(t); } return sum; } - - public static final <T> double sumDouble(List<Double> list) { + + public static <T> double sumDouble(List<Double> list) { double sum = 0; for (double t : list) { sum += t; |
