@Override
      public boolean hasNext() {
        if (cachedHasNext != null) {
          return cachedHasNext;
        }
        boolean hasNext = false;
        for (int i = 0; i < iterators.length; ++i) {
          if (uninitialized) {
            hasNext = !iterators[i].EOF;
            if (hasNext) {
              break;
            }
          } else {
            if (lastReturnedIteratorIndex == i) {
              do {
                iterators[i].move();
                if (iterators[i].EOF) {
                  break;
                } // else if (!this.lastReturned.equals(this.iterators[i].get()))
                  // {
                else if (compare(lastReturned, iterators[i].get()) != 0) {
                  hasNext = true;
                  break;
                }
              } while (true);
            } else {
              do {
                if (iterators[i].EOF) {
                  break;
                } // else if
                  // (!this.iterators[i].get().equals(this.lastReturned)) {
                else if (compare(iterators[i].get(), lastReturned) != 0) {
                  hasNext = true;
                  break;
                } else {
                  iterators[i].move();
                }
              } while (true);
            }
          }
        }
        uninitialized = false;
        cachedHasNext = hasNext;
        return hasNext;
      }
The n - way merge results returns a sorted results on the cumulative sorted results for
partitioned region based query
geode-core/src/main/java/org/apache/geode/cache/query/internal/NWayMergeResults.java