Skip to content

Commit 2421797

Browse files
committed
revert CollectionUtils
1 parent 9f472b7 commit 2421797

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

common/src/main/java/org/tron/common/utils/CollectionUtils.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111

1212
public class CollectionUtils {
1313

14+
public static <K, V> List<V> collectList(Collection<K> items, Function<K, V> collector) {
15+
List<V> collected = new ArrayList<>(items.size());
16+
for (K item : items) {
17+
collected.add(collector.apply(item));
18+
}
19+
return collected;
20+
}
21+
22+
public static <K, V> Set<V> collectSet(Collection<K> items, Function<K, V> collector) {
23+
Set<V> collected = new HashSet<>();
24+
for (K item : items) {
25+
collected.add(collector.apply(item));
26+
}
27+
return collected;
28+
}
29+
1430
public static <T> List<T> truncate(List<T> items, int limit) {
1531
if (limit > items.size()) {
1632
return new ArrayList<>(items);
@@ -49,4 +65,24 @@ public static <T> List<T> truncateRandom(List<T> items, int limit, int confirm)
4965
}
5066
return truncated;
5167
}
68+
69+
public static <T> List<T> selectList(Collection<T> items, Predicate<T> predicate) {
70+
List<T> selected = new ArrayList<>();
71+
for (T item : items) {
72+
if (predicate.test(item)) {
73+
selected.add(item);
74+
}
75+
}
76+
return selected;
77+
}
78+
79+
public static <T> Set<T> selectSet(Collection<T> items, Predicate<T> predicate) {
80+
Set<T> selected = new HashSet<>();
81+
for (T item : items) {
82+
if (predicate.test(item)) {
83+
selected.add(item);
84+
}
85+
}
86+
return selected;
87+
}
5288
}

0 commit comments

Comments
 (0)