use of org.apache.jena.util.iterator.NiceIterator in project jena by apache.
the class ArrayBunch method iterator.
@Override
public ExtendedIterator<Triple> iterator(final HashCommon.NotifyEmpty container) {
// System.err.println( ">> (done)" );
return new NiceIterator<Triple>() {
protected final int initialChanges = changes;
protected int i = size;
protected final Triple[] e = elements;
@Override
public boolean hasNext() {
if (changes > initialChanges)
throw new ConcurrentModificationException();
return i > 0;
}
@Override
public Triple next() {
if (changes > initialChanges)
throw new ConcurrentModificationException();
if (i == 0)
noElements("no elements left in ArrayBunch iteration");
return e[--i];
}
@Override
public void remove() {
if (changes > initialChanges)
throw new ConcurrentModificationException();
// System.err.println( ">> ArrayBunch.iterator::remove" );
// System.err.println( "++ size currently " + size );
// System.err.println( "++ container is " + container );
// System.err.println( "++ selector currently " + i + " (triple " + e[i] + ")" );
int last = --size;
e[i] = e[last];
e[last] = null;
if (size == 0)
container.emptied();
// System.err.println( "++ post remove, triples are:" );
// for (int j = 0; j < size; j += 1) System.err.println( "== " + e[j] );
}
};
}
Aggregations