From 2802f2b560e3e2ee1e29574a3df4d849b0d0b5d5 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 10 Dec 2023 15:42:19 +0100 Subject: DictionaryDecoder: Return a LinkedHashMap in serialized order. Guarantees a predictable iteration order in the returned map. Once we move to Java 21 as a baseline, DictionaryDecoder can declare SequencedMap as its entity type. Change-Id: I8dc52ec1690e85bec27419417d68e447f65398ee --- .../src/main/java/eu/mulk/jgvariant/core/Decoder.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'jgvariant-core/src') diff --git a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java index f605b09..9362487 100644 --- a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java +++ b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java @@ -22,13 +22,8 @@ import java.nio.ByteOrder; import java.nio.channels.Channels; import java.nio.charset.Charset; import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; import java.util.function.Function; import java.util.function.Predicate; import java.util.function.UnaryOperator; @@ -485,7 +480,11 @@ public abstract class Decoder { @Override public @NotNull Map decode(ByteBuffer byteSlice) { List> entries = entryArrayDecoder.decode(byteSlice); - return entries.stream().collect(toMap(Entry::getKey, Entry::getValue)); + Map result = new LinkedHashMap<>(); + for (var entry : entries) { + result.put(entry.getKey(), entry.getValue()); + } + return result; } @Override -- cgit v1.2.3