Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ColumnFamilyResultIterator class to implement 'normal' iterable onto ColumnFamilyResult. #587

Merged
merged 1 commit into from
Feb 19, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Original file line Diff line number Diff line change
@@ -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();
}
}