@@ -59,12 +59,13 @@ public class DBCursor implements Iterator<DBObject> , Iterable<DBObject>, Closea
5959 * @param preference the Read Preference for this query
6060 */
6161 public DBCursor ( DBCollection collection , DBObject q , DBObject k , ReadPreference preference ){
62+ if (collection == null ) {
63+ throw new IllegalArgumentException ("collection is null" );
64+ }
6265 _collection = collection ;
6366 _query = q == null ? new BasicDBObject () : q ;
6467 _keysWanted = k ;
65- if ( _collection != null ){
66- _options = _collection .getOptions ();
67- }
68+ _options = _collection .getOptions ();
6869 _readPref = preference ;
6970 _decoderFact = collection .getDBDecoderFactory ();
7071 }
@@ -346,34 +347,26 @@ private void _check()
346347 if ( _it != null )
347348 return ;
348349
349- if ( _collection != null && _query != null ){
350-
351- _lookForHints ();
352-
353- DBObject foo = _query ;
354- if ( hasSpecialQueryFields () ){
355- foo = _specialFields == null ? new BasicDBObject () : _specialFields ;
350+ _lookForHints ();
356351
357- _addToQueryObject ( foo , "query" , _query , true );
358- _addToQueryObject ( foo , "orderby" , _orderBy , false );
359- if (_hint != null )
360- _addToQueryObject ( foo , "$hint" , _hint );
361- if (_hintDBObj != null )
362- _addToQueryObject ( foo , "$hint" , _hintDBObj );
352+ DBObject foo = _query ;
353+ if (hasSpecialQueryFields ()) {
354+ foo = _specialFields == null ? new BasicDBObject () : _specialFields ;
363355
364- if ( _explain )
365- foo .put ( "$explain" , true );
366- if ( _snapshot )
367- foo .put ( "$snapshot" , true );
368- }
356+ _addToQueryObject (foo , "query" , _query , true );
357+ _addToQueryObject (foo , "orderby" , _orderBy , false );
358+ if (_hint != null )
359+ _addToQueryObject (foo , "$hint" , _hint );
360+ if (_hintDBObj != null )
361+ _addToQueryObject (foo , "$hint" , _hintDBObj );
369362
370- _it = _collection .__find ( foo , _keysWanted , _skip , _batchSize , _limit , _options , _readPref , getDecoder ());
363+ if (_explain )
364+ foo .put ("$explain" , true );
365+ if (_snapshot )
366+ foo .put ("$snapshot" , true );
371367 }
372368
373- if ( _it == null ){
374- _it = (new LinkedList <DBObject >()).iterator ();
375- _fake = true ;
376- }
369+ _it = _collection .__find (foo , _keysWanted , _skip , _batchSize , _limit , _options , _readPref , getDecoder ());
377370 }
378371
379372 // Only create a new decoder if there is a decoder factory explicitly set on the collection. Otherwise return null
@@ -477,9 +470,6 @@ private DBObject _next()
477470 * @return
478471 */
479472 public int numGetMores (){
480- if ( _fake )
481- return 0 ;
482-
483473 if ( _it instanceof DBApiLayer .Result )
484474 return ((DBApiLayer .Result )_it ).numGetMores ();
485475
@@ -491,9 +481,6 @@ public int numGetMores(){
491481 * @return
492482 */
493483 public List <Integer > getSizes (){
494- if ( _fake )
495- return new LinkedList <Integer >();
496-
497484 if ( _it instanceof DBApiLayer .Result )
498485 return ((DBApiLayer .Result )_it ).getSizes ();
499486
@@ -765,7 +752,6 @@ public String toString() {
765752
766753 // ---- result info ----
767754 private Iterator <DBObject > _it = null ;
768- private boolean _fake = false ;
769755
770756 private CursorType _cursorType = null ;
771757 private DBObject _cur = null ;
0 commit comments