CavalliumDBEngine/src/main/java/it/cavallium/dbengine/database/RangeSupplier.java

58 lines
1.1 KiB
Java
Raw Normal View History

package it.cavallium.dbengine.database;
2022-07-15 02:44:50 +02:00
import io.netty5.util.Send;
import java.util.function.Supplier;
2022-06-30 15:06:10 +02:00
public abstract class RangeSupplier implements DiscardingCloseable, Supplier<LLRange> {
public static RangeSupplier of(Supplier<LLRange> supplier) {
return new SimpleSupplier(supplier);
}
public static RangeSupplier ofOwned(LLRange supplier) {
return new CopySupplier(supplier);
}
public static RangeSupplier ofShared(LLRange supplier) {
return new SimpleSupplier(supplier::copy);
}
private static final class SimpleSupplier extends RangeSupplier {
private final Supplier<LLRange> supplier;
public SimpleSupplier(Supplier<LLRange> supplier) {
this.supplier = supplier;
}
@Override
public LLRange get() {
return supplier.get();
}
@Override
public void close() {
}
}
private static final class CopySupplier extends RangeSupplier {
private final LLRange supplier;
public CopySupplier(LLRange supplier) {
this.supplier = supplier;
}
@Override
public LLRange get() {
return supplier.copy();
}
@Override
public void close() {
supplier.close();
}
}
}