Set<Filter> all_filters = getGraph().getFilters();
if (mLastPos >= all_filters.size()) mLastPos = -1;
int pos = 0;
Filter first = null;
int firstNdx = -1;
for (Filter filter : all_filters) {
if (filter.canProcess()) {
if (pos <= mLastPos) {
if (first == null) {
// store the first available filter
first = filter;
firstNdx = pos;
}
} else {
// return the next available filter since last
mLastPos = pos;
return filter;
}
}
pos ++;
}
// going around from the beginning
if (first != null ) {
mLastPos = firstNdx;
return first;
}
// if there is nothing to be scheduled, still keep the previous
// position.
return null;