File tree Expand file tree Collapse file tree 1 file changed +14
-9
lines changed
driver/src/main/com/mongodb Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ public void close() {
4343
4444 @ Override
4545 public boolean hasNext () {
46- return ! needsNewBatch () || batchCursor .hasNext ();
46+ return curBatch != null || batchCursor .hasNext ();
4747 }
4848
4949 @ Override
@@ -52,22 +52,20 @@ public T next() {
5252 throw new NoSuchElementException ();
5353 }
5454
55- if (needsNewBatch () ) {
55+ if (curBatch == null ) {
5656 curBatch = batchCursor .next ();
57- curPos = 0 ;
5857 }
5958
60- return curBatch . get ( curPos ++ );
59+ return getNextInBatch ( );
6160 }
6261
6362 @ Override
6463 public T tryNext () {
65- if (needsNewBatch () ) {
64+ if (curBatch == null ) {
6665 curBatch = batchCursor .tryNext ();
67- curPos = 0 ;
6866 }
6967
70- return curBatch == null ? null : curBatch . get ( curPos ++ );
68+ return curBatch == null ? null : getNextInBatch ( );
7169 }
7270
7371 @ Override
@@ -80,7 +78,14 @@ public ServerAddress getServerAddress() {
8078 return batchCursor .getServerAddress ();
8179 }
8280
83- private boolean needsNewBatch () {
84- return curBatch == null || curPos == curBatch .size ();
81+ private T getNextInBatch () {
82+ T nextInBatch = curBatch .get (curPos );
83+ if (curPos < curBatch .size () - 1 ) {
84+ curPos ++;
85+ } else {
86+ curBatch = null ;
87+ curPos = 0 ;
88+ }
89+ return nextInBatch ;
8590 }
8691}
You can’t perform that action at this time.
0 commit comments