package org.springblade.common.utils;

import cn.hutool.core.collection.CollectionUtil;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class ListUtils {

    public static boolean isEqualList(final Collection list1, final Collection list2) {
        if (list1 == list2) {
            return true;
        }
        if (list1 == null || list2 == null || list1.size() != list2.size()) {
            return false;
        }

        Iterator it1 = list1.iterator();
        Iterator it2 = list2.iterator();
        Object obj1, obj2;

        while (it1.hasNext() && it2.hasNext()) {
            obj1 = it1.next();
            obj2 = it2.next();

            if (!(obj1 == null ? obj2 == null : obj1.equals(obj2))) {
                return false;
            }
        }

        return !(it1.hasNext() || it2.hasNext());
    }

    public static <T> List<List<T>> maxParts(List<T> all, int maxParts) {
        int partSize = all.size() / maxParts;
        if (partSize == 0) {
            partSize = 1;
        }
        return CollectionUtil.split(all ,partSize);
    }

    public static <T> List<List<T>> split(List<T> all, int size) {
        return org.apache.commons.collections4.ListUtils.partition(all, size);
    }

}
