org.aksw.commons.collections.trees.ReclaimingSupplier Maven / Gradle / Ivy
package org.aksw.commons.collections.trees;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Supplier;
public class ReclaimingSupplier implements Supplier {
protected Supplier generator;
protected Set reclaims = new TreeSet();
public ReclaimingSupplier(Supplier generator) {
super();
this.generator = generator;
}
public void reclaim(T item) {
reclaims.add(item);
}
@Override
public T get() {
T result;
Iterator it = reclaims.iterator();
if (it.hasNext()) {
result = it.next();
it.remove();
} else {
result = generator.get();
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy