@ Override public boolean next ( ) { if ( currentScan != null ) { if ( currentScan == s1 ) hasMore1 = s1 . next ( ) ; else if ( currentScan == s2 ) hasMore2 = s2 . next ( ) ; } if ( ! hasMore1 && ! hasMore2 ) return false ; else if ( hasMore1 && hasMore2 ) { // update currentScan currentScan = comp . compare ( s1 , s2 ) < 0 ? s1 : s2 ; } else if ( hasMore1 ) currentScan = s1 ; else if ( hasMore2 ) currentScan = s2 ; return true ; }
Moves to the next record in sorted order . First the current scan is moved to the next record . Then the lowest record of the two scans is found and that scan is chosen to be the new current scan .