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() {
43
43
44
44
@ Override
45
45
public boolean hasNext () {
46
- return ! needsNewBatch () || batchCursor .hasNext ();
46
+ return curBatch != null || batchCursor .hasNext ();
47
47
}
48
48
49
49
@ Override
@@ -52,22 +52,20 @@ public T next() {
52
52
throw new NoSuchElementException ();
53
53
}
54
54
55
- if (needsNewBatch () ) {
55
+ if (curBatch == null ) {
56
56
curBatch = batchCursor .next ();
57
- curPos = 0 ;
58
57
}
59
58
60
- return curBatch . get ( curPos ++ );
59
+ return getNextInBatch ( );
61
60
}
62
61
63
62
@ Override
64
63
public T tryNext () {
65
- if (needsNewBatch () ) {
64
+ if (curBatch == null ) {
66
65
curBatch = batchCursor .tryNext ();
67
- curPos = 0 ;
68
66
}
69
67
70
- return curBatch == null ? null : curBatch . get ( curPos ++ );
68
+ return curBatch == null ? null : getNextInBatch ( );
71
69
}
72
70
73
71
@ Override
@@ -80,7 +78,14 @@ public ServerAddress getServerAddress() {
80
78
return batchCursor .getServerAddress ();
81
79
}
82
80
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 ;
85
90
}
86
91
}
You can’t perform that action at this time.
0 commit comments