io.deephaven.engine.table.impl.util.SizedSafeCloseable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-engine-table Show documentation
Show all versions of deephaven-engine-table Show documentation
Engine Table: Implementation and closely-coupled utilities
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.engine.table.impl.util;
import io.deephaven.util.SafeCloseable;
import java.util.function.IntFunction;
public final class SizedSafeCloseable implements SafeCloseable {
private final IntFunction supplier;
private T closeable;
private int capacity;
public SizedSafeCloseable(IntFunction supplier) {
this.supplier = supplier;
}
public T get() {
return closeable;
}
public T ensureCapacity(int capacity) {
if (capacity > this.capacity) {
if (closeable != null) {
closeable.close();
}
closeable = supplier.apply(capacity);
this.capacity = capacity;
}
return closeable;
}
@Override
public void close() {
if (closeable != null) {
closeable.close();
capacity = 0;
closeable = null;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy