test_class.declarator: comparator
test_class.modifier: private
test_class.original_string: private TypeComparator<Tuple2<Integer, String>> comparator;
test_class.type: TypeComparator<Tuple2<Integer, String>>
test_class.var_name: comparator
test_class.file: flink-runtime/src/test/java/org/apache/flink/runtime/operators/sort/MergeIteratorTest.java
test_class.identifier: MergeIteratorTest
test_case.body: @Test
  	public void testMergeOfTwoStreams() throws Exception
  	{
  		// iterators
  		List<MutableObjectIterator<Tuple2<Integer, String>>> iterators = new ArrayList<>();
  		iterators.add(newIterator(new int[] { 1, 2, 4, 5, 10 }, new String[] { "1", "2", "4", "5", "10" }));
  		iterators.add(newIterator(new int[] { 3, 6, 7, 10, 12 }, new String[] { "3", "6", "7", "10", "12" }));
  		
  		final int[] expected = new int[] {1, 2, 3, 4, 5, 6, 7, 10, 10, 12};
  
  		// comparator
  		TypeComparator<Integer> comparator = new IntComparator(true);
  
  		// merge iterator
  		MutableObjectIterator<Tuple2<Integer, String>> iterator = new MergeIterator<>(iterators, this.comparator);
  
  		// check expected order
  		Tuple2<Integer, String> rec1 = new Tuple2<>();
  		Tuple2<Integer, String> rec2 = new Tuple2<>();
  		int k1 = 0;
  		int k2 = 0;
  		
  		int pos = 1;
  		
  		Assert.assertTrue((rec1 = iterator.next(rec1)) != null);
  		Assert.assertEquals(expected[0], rec1.f0.intValue());
  		
  		while ((rec2 = iterator.next(rec2)) != null) {
  			k1 = rec1.f0;
  			k2 = rec2.f0;
  			
  			Assert.assertTrue(comparator.compare(k1, k2) <= 0);
  			Assert.assertEquals(expected[pos++], k2); 
  			
  			Tuple2<Integer, String> tmp = rec1;
  			rec1 = rec2;
  			rec2 = tmp;
  		}
  	}
test_case.class_method_signature: MergeIteratorTest.testMergeOfTwoStreams()
test_case.full_signature: @Test public void testMergeOfTwoStreams()
test_case.identifier: testMergeOfTwoStreams
test_case.invocations: add newIterator add newIterator assertTrue next assertEquals intValue next assertTrue compare assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testMergeOfTwoStreams()
focal_class.declarator: heap
focal_class.modifier: private final
focal_class.original_string: private final PartialOrderPriorityQueue<HeadStream<E>> heap;
focal_class.type: PartialOrderPriorityQueue<HeadStream<E>>
focal_class.var_name: heap
focal_class.file: flink-runtime/src/main/java/org/apache/flink/runtime/operators/sort/MergeIterator.java
focal_class.identifier: MergeIterator
focal_class.interfaces: implements MutableObjectIterator<E>
focal_class.class_method_signature: MergeIterator.MergeIterator(List<MutableObjectIterator<E>> iterators, TypeComparator<E> comparator)
focal_class.full_signature: public  MergeIterator(List<MutableObjectIterator<E>> iterators, TypeComparator<E> comparator)
focal_class.identifier: MergeIterator
focal_class.modifiers: public
focal_class.parameters: (List<MutableObjectIterator<E>> iterators, TypeComparator<E> comparator)
focal_class.signature:  MergeIterator(List<MutableObjectIterator<E>> iterators, TypeComparator<E> comparator)
focal_class.class_method_signature: MergeIterator.next(E reuse)
focal_class.full_signature: @Override public E next(E reuse)
focal_class.identifier: next
focal_class.modifiers: @Override public
focal_class.parameters: (E reuse)
focal_class.return: E
focal_class.signature: E next(E reuse)
focal_class.class_method_signature: MergeIterator.next()
focal_class.full_signature: @Override public E next()
focal_class.identifier: next
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: E
focal_class.signature: E next()
focal_method.body: @Override
  	public E next(E reuse) throws IOException {
  		/* There are three ways to handle object reuse:
  		 * 1) reuse and return the given object
  		 * 2) ignore the given object and return a new object
  		 * 3) exchange the given object for an existing object
  		 *
  		 * The first option is not available here as the return value has
  		 * already been deserialized from the heap's top iterator. The second
  		 * option avoids object reuse. The third option is implemented below
  		 * by passing the given object to the heap's top iterator into which
  		 * the next value will be deserialized.
  		 */
  
  		if (this.heap.size() > 0) {
  			// get the smallest element
  			final HeadStream<E> top = this.heap.peek();
  			E result = top.getHead();
  
  			// read an element
  			if (!top.nextHead(reuse)) {
  				this.heap.poll();
  			} else {
  				this.heap.adjustTop();
  			}
  			return result;
  		}
  		else {
  			return null;
  		}
  	}
focal_method.class_method_signature: MergeIterator.next(E reuse)
focal_method.full_signature: @Override public E next(E reuse)
focal_method.identifier: next
focal_method.invocations: size peek getHead nextHead poll adjustTop
focal_method.modifiers: @Override public
focal_method.parameters: (E reuse)
focal_method.return: E
focal_method.signature: E next(E reuse)