Make YamlConfiguration insertion-sorted

This ensured that the order of the keys is deterministic and be controlled by the developer.
This commit is contained in:
Christian Koop 2022-06-26 01:38:59 +02:00
parent f6e207cdda
commit 2262652577
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
2 changed files with 5 additions and 4 deletions

View File

@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -37,7 +38,7 @@ public class YamlConfiguration implements IConfiguration, HeaderCommentable, Nod
protected @Nullable Supplier<String> headerComment;
public YamlConfiguration() {
this(new HashMap<>(), new HashMap<>());
this(new LinkedHashMap<>(), new LinkedHashMap<>());
}
protected YamlConfiguration(@NotNull Map<String, Object> values, @NotNull Map<String, Supplier<String>> nodeComments) {

View File

@ -47,7 +47,8 @@ class YamlConfigurationTest {
" - 1\n" +
" - 2\n" +
" - 3\n";
static final String expectedOutYaml = "primitives:\n" +
static final String expectedOutYaml = "foo: bar\n" +
"primitives:\n" +
" int: " + Integer.MIN_VALUE + "\n" +
" long: " + Long.MIN_VALUE + "\n" +
" float: " + Float.MIN_VALUE + "\n" +
@ -69,8 +70,7 @@ class YamlConfigurationTest {
" set:\n" +
" - 1\n" +
" - 2\n" +
" - 3\n" +
"foo: bar\n";
" - 3\n";
@Test
void testYamlParser() {