boolean hasNext ( ) throws DataSourceReadException { if ( ! hasNextComputed ) { boolean stayInLoop ; do { stayInLoop = false ; /* * Prior to reading the first iterator, we loop through all of * the iterators to determine the minimum keyId. The minimum * keyId, stored in currentMin, is used for data retrieval. The * value of currentMin will be null if there is no data to * retrieve. */ if ( i == 0 ) { this . currentMin = null ; for ( DataStreamingEvent < E > elt : this . currentElt ) { currentMin = min ( elt ) ; } } /* * If there is no data to retrieve, we'll return false. If there * is data to retrieve, we'll loop through the iterators and * pull data for the current keyId, which is the keyId field of * currentMin. If there's no data for the current keyId, this * should loop through all of the iterators until their ends, * and set hasNext to false. */ if ( currentMin == null ) { this . hasNext = false ; } else { int n = this . currentElt . size ( ) ; for ( ; i < n ; i ++ ) { DataStreamingEvent < E > elt = this . currentElt . get ( i ) ; if ( elt != null && elt . getKeyId ( ) . equals ( this . currentMin != null ? this . currentMin . getKeyId ( ) : null ) ) { this . result = elt ; this . nextKeyId = elt . getKeyId ( ) ; advance ( i ) ; i ++ ; break ; } } if ( this . i == n && this . result == null ) { this . i = 0 ; stayInLoop = true ; } } } while ( this . hasNext && stayInLoop ) ; this . hasNextComputed = true ; } return hasNext ; }
We loop through the iterators passed into the constructor and return whether the the next item in at least one iterator is for the right keyId .