@Test public void testMergeIterator() { List<Integer> evens = Lists.newArrayList(); List<Integer> odds = Lists.newArrayList(); for (int i = 0; i < 20; i++) { if (i % 2 == 0) { evens.add(i); } else { odds.add(i); } } MergeIterator<Integer> merged = new MergeIterator<Integer>(Lists.<Iterator<Integer>> newArrayList(evens.iterator(), odds.iterator()), integerComparator); assertTrue(merged.hasNext()); for (Integer i = 0; i < 20; i++) { assertTrue(merged.hasNext()); assertEquals(i, merged.next()); } assertFalse(merged.hasNext()); merged = new MergeIterator<Integer>(Lists.<Iterator<Integer>> newArrayList(odds.iterator(), evens.iterator()), integerComparator); assertTrue(merged.hasNext()); for (Integer i = 0; i < 20; i++) { assertTrue(merged.hasNext()); assertEquals(i, merged.next()); } assertFalse(merged.hasNext()); }
private MergeIterator(Comparator<? super T> comparator, int size) { this.comparator = comparator; this.iterators = new ArrayList<>(size); this.iteratorsWithNextValue = new ArrayList<>(size); this.nextValue = null; }
MergeIterator implements Iterator<T> { private MergeIterator(Comparator<? super T> comparator, int size) { this.comparator = comparator; this.iterators = new ArrayList<>(size); this.iteratorsWithNextValue = new ArrayList<>(size); this.nextValue = null; } }
MergeIterator implements Iterator<T> { private MergeIterator(Comparator<? super T> comparator, int size) { this.comparator = comparator; this.iterators = new ArrayList<>(size); this.iteratorsWithNextValue = new ArrayList<>(size); this.nextValue = null; } private  MergeIterator(Comparator<? super T> comparator, int size);  MergeIterator(Comparator<? super T> comparator, @SuppressWarnings("unchecked") Iterator<T>... iterators);  MergeIterator(List<Iterator<T>> iterators, Comparator<? super T> comparator); }
MergeIterator implements Iterator<T> { private MergeIterator(Comparator<? super T> comparator, int size) { this.comparator = comparator; this.iterators = new ArrayList<>(size); this.iteratorsWithNextValue = new ArrayList<>(size); this.nextValue = null; } private  MergeIterator(Comparator<? super T> comparator, int size);  MergeIterator(Comparator<? super T> comparator, @SuppressWarnings("unchecked") Iterator<T>... iterators);  MergeIterator(List<Iterator<T>> iterators, Comparator<? super T> comparator); @Override boolean hasNext(); @Override T next(); }
MergeIterator implements Iterator<T> { private MergeIterator(Comparator<? super T> comparator, int size) { this.comparator = comparator; this.iterators = new ArrayList<>(size); this.iteratorsWithNextValue = new ArrayList<>(size); this.nextValue = null; } private  MergeIterator(Comparator<? super T> comparator, int size);  MergeIterator(Comparator<? super T> comparator, @SuppressWarnings("unchecked") Iterator<T>... iterators);  MergeIterator(List<Iterator<T>> iterators, Comparator<? super T> comparator); @Override boolean hasNext(); @Override T next();  }