This commit is contained in:
Looly 2020-06-28 11:43:58 +08:00
parent 37c2c07164
commit 7a1438fc02
2 changed files with 5 additions and 2 deletions

View File

@ -278,6 +278,7 @@ public class CollUtil {
* @param coll2 集合2 * @param coll2 集合2
* @param otherColls 其它集合 * @param otherColls 其它集合
* @return 并集的集合返回 {@link LinkedHashSet} * @return 并集的集合返回 {@link LinkedHashSet}
* @since 5.3.9
*/ */
@SafeVarargs @SafeVarargs
public static <T> Set<T> intersectionDistinct(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls) { public static <T> Set<T> intersectionDistinct(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls) {
@ -294,9 +295,11 @@ public class CollUtil {
if (ArrayUtil.isNotEmpty(otherColls)) { if (ArrayUtil.isNotEmpty(otherColls)) {
for (Collection<T> otherColl : otherColls) { for (Collection<T> otherColl : otherColls) {
if(isNotEmpty(otherColl)){
result.retainAll(otherColl); result.retainAll(otherColl);
} }
} }
}
return result; return result;
} }

View File

@ -81,7 +81,7 @@ public class CollUtilTest {
} }
@Test @Test
public void intersectionTest2() { public void intersectionDistinctTest() {
ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x"); ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d"); ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d");
ArrayList<String> list3 = CollUtil.newArrayList(); ArrayList<String> list3 = CollUtil.newArrayList();