aboutsummaryrefslogtreecommitdiff
path: root/api/src/main/java/me
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-06-28 19:24:36 +0800
committershedaniel <daniel@shedaniel.me>2022-06-28 19:24:36 +0800
commit3df8ca8d31d6e49373f38075de6235653c006551 (patch)
tree98e208148fb8e0078b8b724f5cc020b6ade50e49 /api/src/main/java/me
parent9c16ebb18d15c93529d860c5615fd968866ef59f (diff)
downloadRoughlyEnoughItems-3df8ca8d31d6e49373f38075de6235653c006551.tar.gz
RoughlyEnoughItems-3df8ca8d31d6e49373f38075de6235653c006551.tar.bz2
RoughlyEnoughItems-3df8ca8d31d6e49373f38075de6235653c006551.zip
Distinct tag entries
Diffstat (limited to 'api/src/main/java/me')
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java15
1 files changed, 13 insertions, 2 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 7a6c3a285..3c05132c6 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
@@ -138,7 +138,7 @@ public class CollectionUtils {
}
return l;
}
-
+
public static <T, R> Set<R> mapToSet(Collection<T> list, Function<T, R> function) {
Set<R> l = new HashSet<>(list.size() + 1);
for (T t : list) {
@@ -146,7 +146,7 @@ public class CollectionUtils {
}
return l;
}
-
+
public static <T, R> Set<R> mapToSet(Iterable<T> list, Function<T, R> function) {
Set<R> l = new HashSet<>();
for (T t : list) {
@@ -349,6 +349,17 @@ public class CollectionUtils {
return sum;
}
+ public static <T> List<T> distinctToList(Iterable<T> list) {
+ List<T> newList = new ArrayList<>();
+ Set<T> set = new HashSet<>();
+ for (T t : list) {
+ if (set.add(t)) {
+ newList.add(t);
+ }
+ }
+ return newList;
+ }
+
public static <T> Iterable<List<T>> partition(List<T> list, int size) {
return () -> new UnmodifiableIterator<List<T>>() {
int i = 0;