All Downloads are FREE. Search and download functionalities are using the official Maven repository.

be.bagofwords.iterator.CloseableIterator Maven / Gradle / Ivy

Go to download

Utility classes that are used in the count-db project and other bow-* projects

There is a newer version: 1.2.0
Show newest version
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