
be.bagofwords.iterator.CloseableIterator 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.io.Closeable;
import java.util.Iterator;
public abstract class CloseableIterator implements Iterator, Closeable {
private boolean wasClosed = false;
private final String creatingMethod;
public CloseableIterator() {
StackTraceElement callingMethod = Thread.currentThread().getStackTrace()[2];
creatingMethod = callingMethod.getFileName() + ":" + callingMethod.getLineNumber();
}
@Override
public void close() {
if (!wasClosed) {
closeInt();
wasClosed = true;
}
}
public boolean wasClosed() {
return wasClosed;
}
protected abstract void closeInt();
public void remove() {
throw new RuntimeException("Not implemented");
}
@Override
protected void finalize() throws Throwable {
super.finalize();
if (!wasClosed) {
UI.writeError("CloseableIterator was not closed! Was created in " + creatingMethod);
close();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy