All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xxl.mathematica.list.Intersection Maven / Gradle / Ivy

package xxl.mathematica.list;

import java.util.Comparator;
import java.util.List;

/**
 * 交集
 */
public class Intersection {
    /**
     * comparable
     *
     * @param list1
     * @param list2
     * @param 
     * @return
     */
    public static > List intersection(List list1, List list2) {
        Comparator comparator = Comparable::compareTo;
        return intersection(list1, list2, comparator);
    }

    /**
     * 两个集合的交集
     *
     * @param list1
     * @param list2
     * @param 
     * @return
     */
    public static  List intersection(List list1, List list2, Comparator comparator) {
        return io.vavr.collection.List.ofAll(list1)
                .distinctBy(comparator)
                .filter(t1 -> io.vavr.collection.List.ofAll(list2)
                        .distinctBy(comparator)
                        .exists(t2 -> comparator.compare(t1, t2) == 0))
                .sorted(comparator)
                .asJava();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy