Minor cleanup.

git-svn-id: https://hyracks.googlecode.com/svn/branches/hyracks_inverted_index_updates_new@1841 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-storage-am-lsm-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexSearchCursor.java b/hyracks-storage-am-lsm-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexSearchCursor.java
index 9215d77..60084da 100644
--- a/hyracks-storage-am-lsm-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexSearchCursor.java
+++ b/hyracks-storage-am-lsm-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexSearchCursor.java
@@ -27,20 +27,20 @@
 import edu.uci.ics.hyracks.storage.am.common.api.IndexException;
 import edu.uci.ics.hyracks.storage.am.lsm.common.impls.LSMHarness;
 
+/**
+ * Searches the components one-by-one, completely consuming a cursor before moving on to the next one.
+ * Therefore, the are no guarantees about sort order of the results.
+ */
 public class LSMInvertedIndexSearchCursor implements IIndexCursor {
 
+    private final List<IIndexCursor> indexCursors = new ArrayList<IIndexCursor>();
     private int cursorIndex = -1;
     private LSMHarness harness;
     private boolean includeMemComponent;
     private AtomicInteger searcherRefCount;
     private List<IIndexAccessor> indexAccessors;
-    private List<IIndexCursor> indexCursors;// = new ArrayList<IIndexCursor>();
     private ISearchPredicate searchPred;
 
-    public LSMInvertedIndexSearchCursor() {
-        indexCursors = new ArrayList<IIndexCursor>();
-    }
-
     @Override
     public void open(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException {
         LSMInvertedIndexCursorInitialState lsmInitialState = (LSMInvertedIndexCursorInitialState) initialState;
@@ -49,15 +49,40 @@
         searcherRefCount = lsmInitialState.getSearcherRefCount();
         indexAccessors = lsmInitialState.getIndexAccessors();
         indexCursors.clear();
-        //        indexCursors = new ArrayList<IIndexCursor>(indexAccessors.size());
         cursorIndex = 0;
         this.searchPred = searchPred;
-
-        IIndexAccessor currentAccessor;
-        IIndexCursor currentCursor;
         while (cursorIndex < indexAccessors.size()) {
             // Open cursors and perform search lazily as each component is passed over
-            currentAccessor = indexAccessors.get(cursorIndex);
+            IIndexAccessor currentAccessor = indexAccessors.get(cursorIndex);
+            IIndexCursor currentCursor = currentAccessor.createSearchCursor();
+            try {
+                currentAccessor.search(currentCursor, searchPred);
+            } catch (IndexException e) {
+                throw new HyracksDataException(e);
+            }
+            indexCursors.add(currentCursor);
+            if (currentCursor.hasNext()) {
+                break;
+            }
+            // Close as we go to release any resources.
+            currentCursor.close();
+            cursorIndex++;
+        }
+    }
+
+    @Override
+    public boolean hasNext() throws HyracksDataException {
+        if (cursorIndex >= indexAccessors.size()) {
+            return false;
+        }
+        IIndexCursor currentCursor = indexCursors.get(cursorIndex);
+        if (currentCursor.hasNext()) {
+            return true;
+        }
+        currentCursor.close();
+        cursorIndex++;
+        while (cursorIndex < indexAccessors.size()) {
+            IIndexAccessor currentAccessor = indexAccessors.get(cursorIndex);
             currentCursor = currentAccessor.createSearchCursor();
             try {
                 currentAccessor.search(currentCursor, searchPred);
@@ -65,67 +90,25 @@
                 throw new HyracksDataException(e);
             }
             indexCursors.add(currentCursor);
-
             if (currentCursor.hasNext()) {
-                break;
+                return true;
             }
-
-            // Close as we go to release any resources
             currentCursor.close();
             cursorIndex++;
         }
-
-    }
-
-    @Override
-    public boolean hasNext() throws HyracksDataException {
-        IIndexAccessor currentAccessor;
-        IIndexCursor currentCursor;
-
-        if (cursorIndex >= indexAccessors.size()) {
-            return false;
-        }
-
-        currentCursor = indexCursors.get(cursorIndex);
-        if (currentCursor.hasNext()) {
-            return true;
-        } else {
-            currentCursor.close();
-            cursorIndex++;
-            while (cursorIndex < indexAccessors.size()) {
-                currentAccessor = indexAccessors.get(cursorIndex);
-                currentCursor = currentAccessor.createSearchCursor();
-                try {
-                    currentAccessor.search(currentCursor, searchPred);
-                } catch (IndexException e) {
-                    throw new HyracksDataException(e);
-                }
-                indexCursors.add(currentCursor);
-
-                if (currentCursor.hasNext()) {
-                    return true;
-                } else {
-                    currentCursor.close();
-                    cursorIndex++;
-                }
-            }
-        }
-
         return false;
     }
 
     @Override
     public void next() throws HyracksDataException {
-        IIndexAccessor currentAccessor;
         IIndexCursor currentCursor = indexCursors.get(cursorIndex);
-
         if (currentCursor.hasNext()) {
             currentCursor.next();
         } else {
             currentCursor.close();
             cursorIndex++;
             while (cursorIndex < indexAccessors.size()) {
-                currentAccessor = indexAccessors.get(cursorIndex);
+                IIndexAccessor currentAccessor = indexAccessors.get(cursorIndex);
                 currentCursor = currentAccessor.createSearchCursor();
                 try {
                     currentAccessor.search(currentCursor, searchPred);
@@ -133,7 +116,6 @@
                     throw new HyracksDataException(e);
                 }
                 indexCursors.add(currentCursor);
-
                 if (currentCursor.hasNext()) {
                     currentCursor.next();
                     break;
@@ -166,9 +148,8 @@
     public ITupleReference getTuple() {
         if (cursorIndex < indexCursors.size()) {
             return indexCursors.get(cursorIndex).getTuple();
-        } else {
-            return null;
         }
+        return null;
     }
 
 }