Use linkedhashmap

This commit is contained in:
Andrea Cavalli 2021-12-18 15:15:19 +01:00
parent 9952eaffc0
commit 1de5e52ffd
2 changed files with 6 additions and 4 deletions

View File

@ -19,6 +19,7 @@ import it.cavallium.dbengine.database.serialization.Serializer;
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength; import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -150,7 +151,7 @@ public class DatabaseMapDictionary<T, U> extends DatabaseMapDictionaryDeep<T, U,
sink.error(ex); sink.error(ex);
} }
}) })
.collectMap(Entry::getKey, Entry::getValue, HashMap::new) .collectMap(Entry::getKey, Entry::getValue, LinkedHashMap::new)
.filter(map -> !map.isEmpty()); .filter(map -> !map.isEmpty());
} }

View File

@ -10,6 +10,7 @@ import it.cavallium.dbengine.database.serialization.KVSerializationFunction;
import it.cavallium.dbengine.database.serialization.SerializationException; import it.cavallium.dbengine.database.serialization.SerializationException;
import it.cavallium.dbengine.database.serialization.SerializationFunction; import it.cavallium.dbengine.database.serialization.SerializationFunction;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects; import java.util.Objects;
@ -187,7 +188,7 @@ public interface DatabaseStageMap<T, U, US extends DatabaseStage<U>> extends Dat
default Mono<Map<T, U>> setAndGetPrevious(Map<T, U> value) { default Mono<Map<T, U>> setAndGetPrevious(Map<T, U> value) {
return this return this
.setAllValuesAndGetPrevious(Flux.fromIterable(Map.copyOf(value).entrySet())) .setAllValuesAndGetPrevious(Flux.fromIterable(Map.copyOf(value).entrySet()))
.collectMap(Entry::getKey, Entry::getValue, HashMap::new) .collectMap(Entry::getKey, Entry::getValue, LinkedHashMap::new)
.filter(map -> !map.isEmpty()); .filter(map -> !map.isEmpty());
} }
@ -209,7 +210,7 @@ public interface DatabaseStageMap<T, U, US extends DatabaseStage<U>> extends Dat
if (updateMode == UpdateMode.ALLOW_UNSAFE) { if (updateMode == UpdateMode.ALLOW_UNSAFE) {
return this return this
.getAllValues(null) .getAllValues(null)
.collectMap(Entry::getKey, Entry::getValue, HashMap::new) .collectMap(Entry::getKey, Entry::getValue, LinkedHashMap::new)
.single() .single()
.<Tuple2<Optional<Map<T, U>>, Optional<Map<T, U>>>>handle((v, sink) -> { .<Tuple2<Optional<Map<T, U>>, Optional<Map<T, U>>>>handle((v, sink) -> {
if (v.isEmpty()) { if (v.isEmpty()) {
@ -255,7 +256,7 @@ public interface DatabaseStageMap<T, U, US extends DatabaseStage<U>> extends Dat
default Mono<Map<T, U>> get(@Nullable CompositeSnapshot snapshot, boolean existsAlmostCertainly) { default Mono<Map<T, U>> get(@Nullable CompositeSnapshot snapshot, boolean existsAlmostCertainly) {
return this return this
.getAllValues(snapshot) .getAllValues(snapshot)
.collectMap(Entry::getKey, Entry::getValue, HashMap::new) .collectMap(Entry::getKey, Entry::getValue, LinkedHashMap::new)
.filter(map -> !map.isEmpty()); .filter(map -> !map.isEmpty());
} }