diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2023-12-10 15:42:19 +0100 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2023-12-10 15:42:47 +0100 |
commit | 2802f2b560e3e2ee1e29574a3df4d849b0d0b5d5 (patch) | |
tree | 26854632c4b93751a3bec16be0b77fc4283b821d /jgvariant-core/src/main/java | |
parent | e9440b54b5442c3b5ef7bffa936152ebbc7b7173 (diff) |
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<K, V> as its entity type.
Change-Id: I8dc52ec1690e85bec27419417d68e447f65398ee
Diffstat (limited to 'jgvariant-core/src/main/java')
-rw-r--r-- | jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java | 13 |
1 files changed, 6 insertions, 7 deletions
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<T> { @Override public @NotNull Map<K, V> decode(ByteBuffer byteSlice) { List<Map.Entry<K, V>> entries = entryArrayDecoder.decode(byteSlice); - return entries.stream().collect(toMap(Entry::getKey, Entry::getValue)); + Map<K, V> result = new LinkedHashMap<>(); + for (var entry : entries) { + result.put(entry.getKey(), entry.getValue()); + } + return result; } @Override |