From 14e00a1857f7dc8f40a047ed8354dabe444dcc22 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Thu, 20 Apr 2023 20:40:04 +0200 Subject: [PATCH] Optimizations --- pom.xml | 2 +- .../cavallium/dbengine/client/MappedSerializer.java | 11 +++++++++++ .../dbengine/client/MappedSerializerFixedLength.java | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0daa7b9..ac9e4cb 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ 9.5.0 8.0.0 5.9.0 - 1.0.7 + 1.0.9 diff --git a/src/main/java/it/cavallium/dbengine/client/MappedSerializer.java b/src/main/java/it/cavallium/dbengine/client/MappedSerializer.java index e41b142..cd906d6 100644 --- a/src/main/java/it/cavallium/dbengine/client/MappedSerializer.java +++ b/src/main/java/it/cavallium/dbengine/client/MappedSerializer.java @@ -5,6 +5,7 @@ import it.cavallium.buffer.BufDataInput; import it.cavallium.buffer.BufDataOutput; import it.cavallium.dbengine.database.serialization.SerializationException; import it.cavallium.dbengine.database.serialization.Serializer; +import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength; import org.jetbrains.annotations.NotNull; public class MappedSerializer implements Serializer { @@ -18,6 +19,16 @@ public class MappedSerializer implements Serializer { this.keyMapper = keyMapper; } + public static Serializer of(Serializer ser, + Mapper keyMapper) { + if (keyMapper.getClass() == NoMapper.class) { + //noinspection unchecked + return (Serializer) ser; + } else { + return new MappedSerializer<>(ser, keyMapper); + } + } + @Override public @NotNull B deserialize(@NotNull BufDataInput in) throws SerializationException { return keyMapper.map(serializer.deserialize(in)); diff --git a/src/main/java/it/cavallium/dbengine/client/MappedSerializerFixedLength.java b/src/main/java/it/cavallium/dbengine/client/MappedSerializerFixedLength.java index d9a1fb7..8b7e42a 100644 --- a/src/main/java/it/cavallium/dbengine/client/MappedSerializerFixedLength.java +++ b/src/main/java/it/cavallium/dbengine/client/MappedSerializerFixedLength.java @@ -18,6 +18,16 @@ public class MappedSerializerFixedLength implements SerializerFixedBinaryL this.keyMapper = keyMapper; } + public static SerializerFixedBinaryLength of(SerializerFixedBinaryLength fixedLengthSerializer, + Mapper keyMapper) { + if (keyMapper.getClass() == NoMapper.class) { + //noinspection unchecked + return (SerializerFixedBinaryLength) fixedLengthSerializer; + } else { + return new MappedSerializerFixedLength<>(fixedLengthSerializer, keyMapper); + } + } + @Override public @NotNull B deserialize(@NotNull BufDataInput in) throws SerializationException { return keyMapper.map(fixedLengthSerializer.deserialize(in));