Question: Need help on a Java Problem. I'm new to Java. I encountered a problem and have no idea how to solve it. The picture below
Need help on a Java Problem. I'm new to Java. I encountered a problem and have no idea how to solve it.
The picture below is code in file that needs to fill [Intersection.java]

Following is the test in file[IntersectionTest.java]
import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; class IntersectionTest { @Test void should_not_contain_elements_that_exist_in_just_one_iterable() { List left = Arrays.asList(1, 2, 2, 3, 3, 3, 4, 4, 4, 4); List right = Arrays.asList(5, 4, 4, 3, 3, 3, 2, 2, 2, 2); final List intersection = Intersection.getIntersection(left, right); assertEquals(0, countAppearance(intersection, 1)); assertEquals(0, countAppearance(intersection, 5)); } @Test void should_get_correct_appearance() { List left = Arrays.asList(1, 2, 2, 3, 3, 3, 4, 4, 4, 4); List right = Arrays.asList(5, 4, 4, 3, 3, 3, 2, 2, 2, 2); final List intersection = Intersection.getIntersection(left, right); assertEquals(2, countAppearance(intersection, 2)); assertEquals(3, countAppearance(intersection, 3)); assertEquals(2, countAppearance(intersection, 4)); } } The following code is in [IntersectionTestUtil.java]
import java.util.List; import java.util.Objects; class IntersectionTestUtil { public static int countAppearance(List list, T item) { return (int)list.stream().filter(i -> Objects.equals(i, item)).count(); } } import java.util.List; public class Intersection { /** *
Returns a {@Link List} containing the intersection of the given {@link Iterablets.
*
The appearance of each element in the returned {@link List} will be equal to the minimum * of the appearance of that element in the two given {@ink Iterable}s.
* * @param left the first collection, must not be null. * @param right the second collection, must not be null. * @param
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
