package net.sourceforge.pain.db;
import java.util.*;
/**
* PAiN Date: 30.03.2003 Time: 20:59:37
*/
final class DbExtentIterator implements Iterator {
private final DbClassImpl dbClass;
private DbObject current;
private int modCount;
DbExtentIterator(final DbClassImpl dbClass) {
this.dbClass = dbClass;
current = null;
modCount = dbClass.modCount;
}
public boolean hasNext() {
checkState();
return (current==null && dbClass.firstInExtent!=null) || (current!=null && current.next != null);
}
private void checkState() {
dbClass.checkDbState();
if (dbClass.modCount != modCount) {
throw new ConcurrentModificationException();
}
}
public Object next() {
checkState();
if (current == null) {
if (dbClass.firstInExtent == null) {
throw new NoSuchElementException();
}
current = dbClass.firstInExtent;
} else {
if (current.next == null) {
throw new NoSuchElementException();
}
current = current.next;
}
return current;
}
public void remove() {
checkState();
if (current == null) {
throw new IllegalStateException();
}
final DbObject victim = current;
current = current.prev;
victim.delete();
modCount = dbClass.modCount;
}
}