|
5 | 5 | import org.jetbrains.annotations.NotNull; |
6 | 6 | import org.jetbrains.annotations.Unmodifiable; |
7 | 7 |
|
| 8 | +import java.util.LinkedHashMap; |
8 | 9 | import java.util.Map; |
9 | 10 | import java.util.Optional; |
10 | 11 | import java.util.UUID; |
11 | | -import java.util.concurrent.ConcurrentHashMap; |
12 | 12 |
|
13 | 13 | public class ValueRegistry { |
14 | | - public static final ValueRegistry REGISTRY = new ValueRegistry() |
15 | | - .register(Boolean.class, new BooleanValue()) |
16 | | - |
17 | | - .register(Byte.class, new ByteValue()) |
18 | | - .register(Short.class, new ShortValue()) |
19 | | - |
20 | | - .register(Integer.class, new IntegerValue()) |
21 | | - .register(Double.class, new DoubleValue()) |
22 | | - .register(Float.class, new FloatValue()) |
23 | | - .register(Long.class, new LongValue()) |
24 | | - |
25 | | - .register(UUID.class, new UUIDValue()) |
26 | | - |
27 | | - .register(Character.class, new CharacterValue()) |
28 | | - .register(String.class, new StringValue()); |
| 14 | + public static final ValueRegistry REGISTRY; |
| 15 | + |
| 16 | + static { |
| 17 | + REGISTRY = new ValueRegistry() |
| 18 | + .register(Boolean.class, new BooleanValue()) |
| 19 | + .register(Byte.class, new ByteValue()) |
| 20 | + .register(Short.class, new ShortValue()) |
| 21 | + .register(Integer.class, new IntegerValue()) |
| 22 | + .register(Double.class, new DoubleValue()) |
| 23 | + .register(Float.class, new FloatValue()) |
| 24 | + .register(Long.class, new LongValue()) |
| 25 | + .register(UUID.class, new UUIDValue()) |
| 26 | + .register(Character.class, new CharacterValue()); |
| 27 | + |
| 28 | + // Ensure String is always registered last. |
| 29 | + REGISTRY.register(String.class, new StringValue()); |
| 30 | + } |
29 | 31 |
|
30 | 32 | private ValueRegistry() {} |
31 | 33 |
|
32 | | - private final Map<Class<?>, InlineValue<?>> inlineRegistry = new ConcurrentHashMap<>(); |
33 | | - private final Map<Class<?>, InscriptValue<?>> inscriptRegistry = new ConcurrentHashMap<>(); |
| 34 | + private final Map<Class<?>, InlineValue<?>> inlineRegistry = new LinkedHashMap<>(); |
| 35 | + private final Map<Class<?>, InscriptValue<?>> inscriptRegistry = new LinkedHashMap<>(); |
34 | 36 |
|
35 | 37 | @NotNull |
36 | 38 | public <T> Optional<InlineValue<T>> getInline(final @NotNull Class<? extends T> ignoredKey) { |
@@ -73,12 +75,12 @@ public <T> ValueRegistry register(final @NotNull Class<? super T> key, final @No |
73 | 75 | @NotNull |
74 | 76 | @Unmodifiable |
75 | 77 | public Map<Class<?>, InlineValue<?>> getInlineRegistry() { |
76 | | - return Map.copyOf(inlineRegistry); |
| 78 | + return new LinkedHashMap<>(inlineRegistry); |
77 | 79 | } |
78 | 80 |
|
79 | 81 | @NotNull |
80 | 82 | @Unmodifiable |
81 | 83 | public Map<Class<?>, InscriptValue<?>> getInscriptRegistry() { |
82 | | - return Map.copyOf(inscriptRegistry); |
| 84 | + return new LinkedHashMap<>(inscriptRegistry); |
83 | 85 | } |
84 | 86 | } |
0 commit comments