MCPcopy Create free account
hub / github.com/0opslab/opslabJutil / CollectionHelper

Class CollectionHelper

src/main/java/com/opslab/helper/CollectionHelper.java:14–336  ·  view source on GitHub ↗

集合对象的一些助手工具类

Source from the content-addressed store, hash-verified

12 * 集合对象的一些助手工具类
13 */
14public final class CollectionHelper {
15 private static Logger logger = LoggerFactory.getLogger(CollectionHelper.class);
16
17 /**
18 * 对集合中元素进行特定的处理
19 *
20 * @param collection 集合
21 * @param handler 实现特定处理的方法
22 * @param <T> 泛型
23 */
24 public static <T> void handler(Collection<T> collection, ObjectHandler<T> handler) {
25 if (collection == null || collection.size() == 0) {
26 logger.error("collection is empty or is null");
27 return;
28 }
29 for (T t : collection) {
30 handler.handler(t);
31 }
32 }
33
34 /**
35 * 对集合中的元素进行特定的处理,并获得处理后的结果
36 *
37 * @param collection 待处理的集合
38 * @param result 接受处理后结果的集合
39 * @param process 实现的特定处理
40 * @param <T> 泛型
41 * @param <E> 泛型
42 */
43 public static <T, E> void process(Collection<T> collection, Collection<E> result, ObjectProcess<T, E> process) {
44 if (collection == null || collection.size() == 0) {
45 logger.error("collection is empty or is null");
46 return;
47 }
48 if (result == null || result.size() == 0) {
49 logger.error("receive collection is empty or is null");
50 return;
51 }
52 for (T t : collection) {
53 E next = process.process(t);
54 if (next != null) {
55 result.add(next);
56 }
57 }
58 }
59
60 /**
61 * 去除重复元素
62 *
63 * @param list 需要处理的list
64 * @param <T> 泛型方法
65 * @return 去重后的list
66 */
67 public static <T> List<T> removeDuplicate(List<T> list) {
68 if (list == null || list.size() == 0) {
69 logger.error("list is empty or is null");
70 return new ArrayList<>();
71 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected