// Path: src/main/java/net/kimleo/rec/v2/utils/Streams.java
// public class Streams {
//     public static <T extends Comparable<T>> Stream<T> merge(Stream<T> first,
//                                                             Stream<T> second) {
//         MergeIterator<T> iterator = new MergeIterator<>(
//                 first.iterator(), second.iterator(), Comparable::compareTo);
//         IteratingSpliteratorAdapter<T> adapter = new IteratingSpliteratorAdapter<>(iterator);
//         return StreamSupport.stream(adapter, false);
//     }
// 
//     public static <T extends Comparable<T>> Stream<T> merge(Stream<T> first,
//                                                             Stream<T> second,
//                                                             Comparator<T> comparator) {
//         MergeIterator<T> iterator = new MergeIterator<>(
//                 first.iterator(), second.iterator(), comparator);
//         IteratingSpliteratorAdapter<T> adapter = new IteratingSpliteratorAdapter<>(iterator);
//         return StreamSupport.stream(adapter, false);
//     }
// 
// }


import net.kimleo.rec.v2.utils.Streams;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
package net.kimleo.rec.v2.stream;




public class MergeIteratorTest {

    private final List<Integer> first = Arrays.asList(1, 2, 3, 4, 5);
    private final List<Integer> second = Arrays.asList(2, 4, 6, 8, 10);

    @Test
    public void shouldMerge() throws Exception {

        MergeIterator<Integer> merged = new MergeIterator<>(
                first.iterator(), second.iterator(), Integer::compareTo);

        ArrayList<Integer> ints = new ArrayList<>();

        while (merged.hasNext()) {
            ints.add(merged.next());
        }

        assertThat(ints.get(0), is(1));
        assertThat(ints.get(9), is(10));
        assertThat(ints.get(5), is(4));
    }

    @Test
    public void shouldMergeStream() throws Exception {
// Path: src/main/java/net/kimleo/rec/v2/utils/Streams.java
// public class Streams {
//     public static <T extends Comparable<T>> Stream<T> merge(Stream<T> first,
//                                                             Stream<T> second) {
//         MergeIterator<T> iterator = new MergeIterator<>(
//                 first.iterator(), second.iterator(), Comparable::compareTo);
//         IteratingSpliteratorAdapter<T> adapter = new IteratingSpliteratorAdapter<>(iterator);
//         return StreamSupport.stream(adapter, false);
//     }
// 
//     public static <T extends Comparable<T>> Stream<T> merge(Stream<T> first,
//                                                             Stream<T> second,
//                                                             Comparator<T> comparator) {
//         MergeIterator<T> iterator = new MergeIterator<>(
//                 first.iterator(), second.iterator(), comparator);
//         IteratingSpliteratorAdapter<T> adapter = new IteratingSpliteratorAdapter<>(iterator);
//         return StreamSupport.stream(adapter, false);
//     }
// 
// }


// Path: src/test/java/net/kimleo/rec/v2/stream/MergeIteratorTest.java
import net.kimleo.rec.v2.utils.Streams;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

package net.kimleo.rec.v2.stream;




public class MergeIteratorTest {

    private final List<Integer> first = Arrays.asList(1, 2, 3, 4, 5);
    private final List<Integer> second = Arrays.asList(2, 4, 6, 8, 10);

    @Test
    public void shouldMerge() throws Exception {

        MergeIterator<Integer> merged = new MergeIterator<>(
                first.iterator(), second.iterator(), Integer::compareTo);

        ArrayList<Integer> ints = new ArrayList<>();

        while (merged.hasNext()) {
            ints.add(merged.next());
        }

        assertThat(ints.get(0), is(1));
        assertThat(ints.get(9), is(10));
        assertThat(ints.get(5), is(4));
    }

    @Test
    public void shouldMergeStream() throws Exception {
        Stream<Integer> merged = Streams.merge(first.stream(), second.stream());