2022-05-20 10:20:00 +02:00
|
|
|
package it.cavallium.dbengine.database;
|
|
|
|
|
2022-07-15 02:44:50 +02:00
|
|
|
import io.netty5.util.Send;
|
2022-05-20 10:20:00 +02:00
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
2022-06-30 15:06:10 +02:00
|
|
|
public abstract class RangeSupplier implements DiscardingCloseable, Supplier<LLRange> {
|
2022-05-20 10:20:00 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|