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

53 lines
1.5 KiB
Java
Raw Normal View History

2021-02-04 00:48:49 +01:00
package it.cavallium.dbengine.database.collections;
2021-08-29 23:18:03 +02:00
import io.netty.buffer.api.Buffer;
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();
2021-08-29 23:18:03 +02:00
public static final Serializer<Nothing, Buffer> NOTHING_SERIALIZER = new Serializer<>() {
2021-02-04 00:48:49 +01:00
@Override
2021-08-29 23:18:03 +02:00
public @NotNull Nothing deserialize(@NotNull Buffer serialized) {
2021-08-28 22:42:51 +02:00
try {
return NOTHING;
} finally {
serialized.release();
}
2021-02-04 00:48:49 +01:00
}
@Override
2021-08-29 23:18:03 +02:00
public @NotNull Buffer 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() {
}
2021-08-29 23:18:03 +02:00
public static DatabaseStageEntry<Nothing> create(LLDictionary dictionary, Buffer 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() {
}
}
}