com.geotab.util.CollectionUtil Maven / Gradle / Ivy
package com.geotab.util;
import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.experimental.UtilityClass;
@UtilityClass
public class CollectionUtil {
public static List> intersect(List> firstList, List> secondList) {
if (firstList == null || secondList == null) {
return Collections.EMPTY_LIST;
}
Set> intersection = firstList.stream()
.distinct()
.filter(secondList::contains)
.collect(Collectors.toSet());
return Lists.newArrayList(intersection);
}
public static boolean isEmpty(Collection collection) {
return collection == null || collection.isEmpty();
}
}