From 77f2d51068d22b29e144e23a29c63c87466ddca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jyri-Matti=20La=CC=88hteenma=CC=88ki?= Date: Tue, 17 Sep 2024 15:45:41 +0300 Subject: [PATCH] whoops, intersection of iterable returned always empty set --- pom.xml | 2 +- .../java/fi/solita/utils/functional/FunctionalS.java | 2 +- .../fi/solita/utils/functional/FunctionalTest.java | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e74ea67..9460817 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 fi.solita.utils functional-utils - 0.12.53 + 0.12.54 diff --git a/src/main/java/fi/solita/utils/functional/FunctionalS.java b/src/main/java/fi/solita/utils/functional/FunctionalS.java index 823377f..db22f40 100644 --- a/src/main/java/fi/solita/utils/functional/FunctionalS.java +++ b/src/main/java/fi/solita/utils/functional/FunctionalS.java @@ -225,7 +225,7 @@ public static final Set intersection(Set e1, Set e2, Set e3, Set * @return Set intersection of Sets in {@code es}. */ public static final Set intersection(Iterable> es) { - return FunctionalImpl.fold(Collections.emptySet(), SemiGroups.setIntersection(), es); + return FunctionalImpl.fold(SemiGroups.setIntersection(), es).getOrElse(Collections.emptySet()); } diff --git a/src/test/java/fi/solita/utils/functional/FunctionalTest.java b/src/test/java/fi/solita/utils/functional/FunctionalTest.java index 997025d..d708369 100644 --- a/src/test/java/fi/solita/utils/functional/FunctionalTest.java +++ b/src/test/java/fi/solita/utils/functional/FunctionalTest.java @@ -1,5 +1,6 @@ package fi.solita.utils.functional; import static fi.solita.utils.functional.Collections.emptyList; +import static fi.solita.utils.functional.Collections.emptySet; import static fi.solita.utils.functional.Collections.newList; import static fi.solita.utils.functional.Collections.newMutableList; import static fi.solita.utils.functional.Collections.newSet; @@ -412,4 +413,14 @@ public void padRight() { assertEquals("xx", Functional.padRight(2, '0', "xx").toString()); assertEquals("xxx", Functional.padRight(2, '0', "xxx").toString()); } + + @Test + public void testIntersection() { + assertEquals(emptySet(), Functional.intersection(Collections.emptySet(), newSet(2,3))); + assertEquals(emptySet(), Functional.intersection(newSet(2,3), Collections.emptySet())); + assertEquals(emptySet(), Functional.intersection(Arrays.asList(Collections.emptySet(), newSet(2,3)))); + + assertEquals(newSet(2), Functional.intersection(newSet(1,2), newSet(2,3))); + assertEquals(newSet(2), Functional.intersection(Arrays.asList(newSet(1,2), newSet(2,3)))); + } }