package lc.mecha.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ListUtil {
    public static <T> List<List<T>> chopped(List<T> list, final int L) {
        List<List<T>> parts = new ArrayList<>();
        final int N = list.size();
        for (int i = 0; i < N; i += L) {
            parts.add(new ArrayList<>(
                    list.subList(i, Math.min(N, i + L)))
            );
        }
        return parts;
    }

    public static void unique(List dst, List dupes, Collection src) {
        for (Object o : src) {
            if (!dst.contains(o)) {
                dst.add(o);
            } else {
                dupes.add(o);
            }
        }
    }
}
