Skip to content
This repository
Browse code

Merge pull request #587 from ctcttest/master

ColumnFamilyResultIterator class to implement 'normal' iterable onto ColumnFamilyResult.
  • Loading branch information...
commit 7cf189b76b8e58c20793e4814e2211c2d3448dfe 2 parents 6285932 + 9bb791e
Nate McCall authored February 19, 2013
70  core/src/main/java/me/prettyprint/cassandra/service/template/ColumnFamilyResultIterator.java
... ...
@@ -0,0 +1,70 @@
  1
+/**
  2
+ * This class will instill 'normal' iterator behavior to a ColumnFamilyResult.
  3
+ * Simply instantiate this class while passing your ColumnFamilyResult as a 
  4
+ * constructor argument.
  5
+ * 
  6
+ * Ex.
  7
+ * 
  8
+ * ColumnFamilyResultIterator myResultsInterator = 
  9
+ *      new ColumnFamilyResultIterator(someColumnFamilyResult);
  10
+ * 
  11
+ * You can then use myResultsInterator with for loops or iterate with a while loop 
  12
+ * just as with any standard java iterator. 
  13
+ * 
  14
+ */
  15
+package me.prettyprint.cassandra.service.template;
  16
+
  17
+import java.util.Iterator;
  18
+
  19
+import me.prettyprint.cassandra.service.template.ColumnFamilyResult;
  20
+
  21
+public class ColumnFamilyResultIterator implements Iterator<ColumnFamilyResult<?,?>> {
  22
+        private ColumnFamilyResult<?, ?> res;
  23
+        private boolean isStart = true;
  24
+
  25
+        public ColumnFamilyResultIterator(ColumnFamilyResult<?, ?> res) {
  26
+            this.res = res;
  27
+        }
  28
+        
  29
+        public boolean hasNext()
  30
+        {
  31
+            boolean retval = false;
  32
+            if (isStart)
  33
+            {
  34
+                retval = res.hasResults();
  35
+            }
  36
+            else
  37
+            {
  38
+                retval = res.hasNext();
  39
+            }
  40
+            return retval;
  41
+        }
  42
+
  43
+        public ColumnFamilyResult<?, ?> getRes()
  44
+        {
  45
+            return res;
  46
+        }
  47
+
  48
+        public void setRes(ColumnFamilyResult<?, ?> res)
  49
+        {
  50
+            this.res = res;
  51
+        }
  52
+
  53
+        public ColumnFamilyResult<?, ?> next()
  54
+        {
  55
+            if (isStart) 
  56
+            {
  57
+                isStart = false;
  58
+                return res;
  59
+            }
  60
+            else 
  61
+            {
  62
+                return (ColumnFamilyResult<?, ?>) res.next();
  63
+            }
  64
+        }
  65
+        
  66
+        public void remove()
  67
+        {
  68
+            res.remove();
  69
+        }
  70
+}

0 notes on commit 7cf189b

Please sign in to comment.
Something went wrong with that request. Please try again.