package com.yeejoin.amos.boot.biz.common;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test {

    public static void main(String[] args) {
        // 找出重复数据
        //findDuplicateIds(idList, idsToRemove);
        //剔除重复数据
        notInIdList(idList, idsToRemove);
    }

    // 要剔除的ID集合
    static List<String> idsToRemove = Arrays.asList(
            "fdd757d9-c28a-4b7b-8567-882ffe0874be",
            "86a7c5cb-cef6-442c-acde-408052ea92d2"
    );
    // 初始的 ID 列表
    static List<String> idList = new ArrayList<>(Arrays.asList(
            "a73a47e0-e5bd-4d82-b4fa-db56ff5e1aec",
            "71cd3623-a5ab-4e29-9c6d-6962af6ec7ae",
            "56eda391-6b63-4512-9ca3-a2e91cd0bd1c",
            "4b73d406-ef36-4249-8bb9-7a0f9fc0bc83"
    ));

    private static void removeDuplicateIds(List<String> idList, List<String> idsToRemove) {
        // 剔除多个 ID
        System.out.println("初始集合总数: " + idList.size());
        System.out.println("对比集合总数: " + idsToRemove.size());
        idList.removeAll(idsToRemove);
        System.out.println("剔除重复的ID总数: " + idList.size());
        System.out.println("剩余 ID:");
        idList.forEach(id -> System.out.println("'" + id + "',"));
    }


    private static void findDuplicateIds(List<String> idList, List<String> idsToRemove) {
        // 找出重复的 ID
        System.out.println("初始集合总数: " + idList.size());
        System.out.println("对比集合总数: " + idsToRemove.size());
        List<String> duplicateIds = new ArrayList<>(idList);
        duplicateIds.retainAll(idsToRemove);
        System.out.println("重复ID 总数: " + duplicateIds.size());
        System.out.println("重复的 ID:");
        duplicateIds.forEach(id -> System.out.println("\"" + id + "\","));
    }

    private static void notInIdList(List<String> idList, List<String> idsToRemove) {
        // 复制 idsToRemove 并移除所有在 idList 中存在的元素
        List<String> notInIdList = new ArrayList<>(idList);
        notInIdList.removeAll(idsToRemove);

        // 输出结果
        System.out.println("idsToRemove 中不在 idList 中的 ID 总数: " + notInIdList.size());
        System.out.println("不在 idList 中的 ID:");
        notInIdList.forEach(id -> System.out.println("\"" + id + "\","));
    }
}
