
be.bagofwords.iterator.MultipleSwipesIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bow-utils Show documentation
Show all versions of bow-utils Show documentation
Utility classes that are used in the count-db project and other bow-* projects
package be.bagofwords.iterator;
import be.bagofwords.ui.UI;
import java.util.Iterator;
public class MultipleSwipesIterator implements Iterator {
private final DataIterable iterable;
private Iterator currIt;
private T currObj;
private final int numOfSwipes;
private int currentSwipe;
public MultipleSwipesIterator(DataIterable iterable, int numOfSwipes) {
this.iterable = iterable;
this.numOfSwipes = numOfSwipes;
currentSwipe = 0;
currIt = iterable.iterator();
currObj = findNext();
}
private T findNext() {
while (currentSwipe < numOfSwipes) {
if (currIt.hasNext()) {
return currIt.next();
} else {
UI.write("Finished swipe " + currentSwipe + " of " + numOfSwipes);
currentSwipe++;
if (currentSwipe < numOfSwipes) {
currIt = iterable.iterator();
}
}
}
return null;
}
public int getCurrentSwipe() {
return currentSwipe;
}
@Override
public boolean hasNext() {
return currObj != null;
}
@Override
public T next() {
T result = currObj;
currObj = findNext();
return result;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy