|
@@ -0,0 +1,57 @@
|
|
|
+package com.persagy.fm.common.utils;
|
|
|
+
|
|
|
+import org.apache.poi.ss.formula.functions.T;
|
|
|
+import org.assertj.core.util.Lists;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * list工具类
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/4/6 10:52 上午
|
|
|
+ **/
|
|
|
+public class ListUtil {
|
|
|
+ /**
|
|
|
+ * 获取listAfter对比listBefore新增的元素
|
|
|
+ * 使用遍历进行对比,性能有待提升,不适合大数据量对比
|
|
|
+ *
|
|
|
+ * @param listBefore listBefore
|
|
|
+ * @param listAfter listAfter
|
|
|
+ * @return 新增的元素
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/4/6 10:58 上午
|
|
|
+ */
|
|
|
+ public static <T> List<T> getAddedList(List<T> listBefore, List<T> listAfter) {
|
|
|
+ if (CollectionUtils.isEmpty(listAfter)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(listBefore)) {
|
|
|
+ return listAfter;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<T> result = Lists.newArrayList();
|
|
|
+ listAfter.forEach(t -> {
|
|
|
+ // 如果listAfter中的元素不在listBefore中,认为是新增的元素
|
|
|
+ if (!listBefore.contains(t)) {
|
|
|
+ result.add(t);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取listAfter对比listBefore删除的元素
|
|
|
+ * 使用遍历进行对比,性能有待提升,不适合大数据量对比
|
|
|
+ *
|
|
|
+ * @param listBefore listBefore
|
|
|
+ * @param listAfter listAfter
|
|
|
+ * @return 删除的元素
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/4/6 10:58 上午
|
|
|
+ */
|
|
|
+ public static <T> List<T> getDeletedList(List<T> listBefore, List<T> listAfter) {
|
|
|
+ return getAddedList(listAfter, listBefore);
|
|
|
+ }
|
|
|
+}
|