Permalink
Browse files

Merge pull request #587 from ctcttest/master

ColumnFamilyResultIterator class to implement 'normal' iterable onto ColumnFamilyResult.
  • Loading branch information...
zznate committed Feb 19, 2013
2 parents 6285932 + 9bb791e commit 7cf189b76b8e58c20793e4814e2211c2d3448dfe
@@ -0,0 +1,70 @@
+/**
+ * This class will instill 'normal' iterator behavior to a ColumnFamilyResult.
+ * Simply instantiate this class while passing your ColumnFamilyResult as a
+ * constructor argument.
+ *
+ * Ex.
+ *
+ * ColumnFamilyResultIterator myResultsInterator =
+ * new ColumnFamilyResultIterator(someColumnFamilyResult);
+ *
+ * You can then use myResultsInterator with for loops or iterate with a while loop
+ * just as with any standard java iterator.
+ *
+ */
+package me.prettyprint.cassandra.service.template;
+
+import java.util.Iterator;
+
+import me.prettyprint.cassandra.service.template.ColumnFamilyResult;
+
+public class ColumnFamilyResultIterator implements Iterator<ColumnFamilyResult<?,?>> {
+ private ColumnFamilyResult<?, ?> res;
+ private boolean isStart = true;
+
+ public ColumnFamilyResultIterator(ColumnFamilyResult<?, ?> res) {
+ this.res = res;
+ }
+
+ public boolean hasNext()
+ {
+ boolean retval = false;
+ if (isStart)
+ {
+ retval = res.hasResults();
+ }
+ else
+ {
+ retval = res.hasNext();
+ }
+ return retval;
+ }
+
+ public ColumnFamilyResult<?, ?> getRes()
+ {
+ return res;
+ }
+
+ public void setRes(ColumnFamilyResult<?, ?> res)
+ {
+ this.res = res;
+ }
+
+ public ColumnFamilyResult<?, ?> next()
+ {
+ if (isStart)
+ {
+ isStart = false;
+ return res;
+ }
+ else
+ {
+ return (ColumnFamilyResult<?, ?>) res.next();
+ }
+ }
+
+ public void remove()
+ {
+ res.remove();
+ }
+}

0 comments on commit 7cf189b

Please sign in to comment.