SpillingResettableIterator implements ResettableIterator<T> { @Override public boolean hasNext() { if (this.next == null) { if (this.inView != null) { if (this.currentElementNum < this.elementCount) { try { this.serializer.deserialize(this.instance, this.inView); } catch (IOException e) { throw new RuntimeException("SpillingIterator: Error reading element from buffer.", e); } this.next = this.instance; this.currentElementNum++; return true; } else { return false; } } else { if (this.input.hasNext()) { this.next = this.input.next(); try { this.serializer.serialize(this.next, this.buffer); } catch (IOException e) { throw new RuntimeException("SpillingIterator: Error writing element to buffer.", e); } this.elementCount++; return true; } else { return false; } } } else { return true; } } SpillingResettableIterator(Iterator<T> input, TypeSerializer<T> serializer, 
			MemoryManager memoryManager, IOManager ioManager,
			long availableMemory, AbstractInvokable parentTask);  SpillingResettableIterator(Iterator<T> input, TypeSerializer<T> serializer,
			MemoryManager memoryManager, IOManager ioManager, List<MemorySegment> memory); private  SpillingResettableIterator(Iterator<T> input, TypeSerializer<T> serializer,
			MemoryManager memoryManager, IOManager ioManager,
			List<MemorySegment> memory, boolean releaseMemOnClose); void open(); void reset(); @Override boolean hasNext(); @Override T next(); @Override void remove(); List<MemorySegment> close();  }
@Test public void testHasNext() { try { SpillingResettableIterator<PactInteger> iterator = new SpillingResettableIterator<PactInteger>( this.reader, this.serializer, this.memman, this.ioman, 2 * 32 * 1024, this.memOwner); try { iterator.open(); } catch (IOException e) { Assert.fail("Could not open resettable iterator:" + e.getMessage()); } int cnt = 0; while (iterator.hasNext()) { iterator.hasNext(); iterator.next(); cnt++; } Assert.assertTrue(cnt + " elements read from iterator, but " + NUM_TESTRECORDS + " expected", cnt == NUM_TESTRECORDS); iterator.close(); } catch (Exception ex) { ex.printStackTrace(); Assert.fail("Test encountered an exception."); } }