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

49 lines
1.5 KiB
Java
Raw Normal View History

2021-02-04 00:48:49 +01:00
package it.cavallium.dbengine.database.collections;
import io.netty.buffer.ByteBuf;
2021-02-04 00:48:49 +01:00
import it.cavallium.dbengine.database.LLDictionary;
import it.cavallium.dbengine.database.serialization.Serializer;
2021-04-12 17:09:55 +02:00
import java.util.function.Function;
2021-02-04 00:48:49 +01:00
import org.jetbrains.annotations.NotNull;
import static io.netty.buffer.Unpooled.*;
2021-02-04 00:48:49 +01:00
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();
public static final Serializer<Nothing, ByteBuf> NOTHING_SERIALIZER = new Serializer<>() {
2021-02-04 00:48:49 +01:00
@Override
public @NotNull Nothing deserialize(@NotNull ByteBuf serialized) {
2021-02-04 00:48:49 +01:00
return NOTHING;
}
@Override
public @NotNull ByteBuf serialize(@NotNull Nothing deserialized) {
return EMPTY_BUFFER;
2021-02-04 00:48:49 +01:00
}
};
2021-04-12 17:09:55 +02:00
public static final Function<Nothing, Nothing> NOTHING_HASH_FUNCTION = nothing -> nothing;
private static final SubStageGetter<Nothing, DatabaseStageEntry<Nothing>> NOTHING_SUB_STAGE_GETTER
= new SubStageGetterSingle<>(NOTHING_SERIALIZER);
2021-02-04 00:48:49 +01:00
private DatabaseEmpty() {
}
public static DatabaseStageEntry<Nothing> create(LLDictionary dictionary, ByteBuf key) {
2021-02-04 00:48:49 +01:00
return new DatabaseSingle<>(dictionary, key, NOTHING_SERIALIZER);
}
public static SubStageGetter<Nothing, DatabaseStageEntry<Nothing>> createSubStageGetter() {
return NOTHING_SUB_STAGE_GETTER;
}
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() {
}
}
}