CavalliumDBEngine/src/main/java/it/cavallium/dbengine/database/collections/DatabaseEmpty.java

52 lines
1.3 KiB
Java
Raw Normal View History

2021-02-04 00:48:49 +01:00
package it.cavallium.dbengine.database.collections;
2022-10-02 03:09:50 +02:00
import io.netty5.buffer.Buffer;
import io.netty5.buffer.BufferAllocator;
import it.cavallium.dbengine.database.BufSupplier;
2021-02-04 00:48:49 +01:00
import it.cavallium.dbengine.database.LLDictionary;
import it.cavallium.dbengine.database.serialization.Serializer;
import java.util.function.Supplier;
2021-02-04 00:48:49 +01:00
import org.jetbrains.annotations.NotNull;
public class DatabaseEmpty {
2021-04-03 19:09:06 +02:00
@SuppressWarnings({"unused", "InstantiationOfUtilityClass"})
2021-02-04 00:48:49 +01:00
public static final Nothing NOTHING = new Nothing();
2021-09-02 17:15:40 +02:00
public static Serializer<Nothing> nothingSerializer(BufferAllocator bufferAllocator) {
2021-08-31 09:14:46 +02:00
return new Serializer<>() {
2021-10-19 00:22:05 +02:00
2021-08-31 09:14:46 +02:00
@Override
2021-10-19 00:22:05 +02:00
public @NotNull Nothing deserialize(@NotNull Buffer serialized) {
return NOTHING;
}
@Override
public void serialize(@NotNull Nothing deserialized, Buffer output) {
2021-08-31 09:14:46 +02:00
}
2021-02-04 00:48:49 +01:00
2021-08-31 09:14:46 +02:00
@Override
2021-10-19 00:22:05 +02:00
public int getSerializedSizeHint() {
return 0;
2021-08-31 09:14:46 +02:00
}
};
2021-02-04 00:48:49 +01:00
}
2021-08-31 09:14:46 +02:00
private DatabaseEmpty() {
2021-02-04 00:48:49 +01:00
}
2022-07-19 23:45:39 +02:00
public static DatabaseStageEntry<Nothing> create(LLDictionary dictionary, BufSupplier key) {
return new DatabaseMapSingle<>(dictionary, key, nothingSerializer(dictionary.getAllocator()));
2021-02-04 00:48:49 +01:00
}
public static final class Nothing {
2021-02-06 15:53:10 +01:00
@SuppressWarnings("InstantiationOfUtilityClass")
public static Nothing INSTANCE = new Nothing();
2021-02-04 00:48:49 +01:00
private Nothing() {
}
}
}