Skip to content

Commit

Permalink
hocon: cleanup patch 0002
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Nov 8, 2023
1 parent 52b80ba commit 3346c6f
Showing 1 changed file with 36 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,6 @@ Subject: [PATCH] Don't sort configs by key & use deterministic order data
structures


diff --git a/config/src/main/java/com/typesafe/config/impl/ConfigBeanImpl.java b/config/src/main/java/com/typesafe/config/impl/ConfigBeanImpl.java
index 329c7c9c4dc8f097940e200575180bc58af4fbf3..f77bc1ec823777863962083eae09924d90117f0f 100644
--- a/config/src/main/java/com/typesafe/config/impl/ConfigBeanImpl.java
+++ b/config/src/main/java/com/typesafe/config/impl/ConfigBeanImpl.java
@@ -10,8 +10,8 @@ import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.time.Duration;
@@ -45,8 +45,8 @@ public class ConfigBeanImpl {
throw new ConfigException.NotResolved(
"need to Config#resolve() a config before using it to initialize a bean, see the API docs for Config#resolve()");

- Map<String, AbstractConfigValue> configProps = new HashMap<String, AbstractConfigValue>();
- Map<String, String> originalNames = new HashMap<String, String>();
+ Map<String, AbstractConfigValue> configProps = new LinkedHashMap<String, AbstractConfigValue>();
+ Map<String, String> originalNames = new LinkedHashMap<String, String>();
for (Map.Entry<String, ConfigValue> configProp : config.root().entrySet()) {
String originalName = configProp.getKey();
String camelName = ConfigImplUtil.toCamelCase(originalName);
@@ -193,7 +193,7 @@ public class ConfigBeanImpl {
}

private static Object getSetValue(Class<?> beanClass, Type parameterType, Class<?> parameterClass, Config config, String configPropName) {
- return new HashSet((List) getListValue(beanClass, parameterType, parameterClass, config, configPropName));
+ return new LinkedHashSet((List) getListValue(beanClass, parameterType, parameterClass, config, configPropName));
}

private static Object getListValue(Class<?> beanClass, Type parameterType, Class<?> parameterClass, Config config, String configPropName) {
diff --git a/config/src/main/java/com/typesafe/config/impl/ConfigDocumentParser.java b/config/src/main/java/com/typesafe/config/impl/ConfigDocumentParser.java
index 29ffc70a1353f47fd8a59a5816e5bdf4c1b73856..ce4fcc60c24effd6239de9516d168640e6eb2504 100644
--- a/config/src/main/java/com/typesafe/config/impl/ConfigDocumentParser.java
Expand Down Expand Up @@ -127,27 +92,53 @@ index 1e562ace21d6ae66b47f7cb51a7a16d2b68f8f59..519ddafe9408845fec9ebb81d5f03e3e
boolean lastWasNewline = false;

diff --git a/config/src/main/java/com/typesafe/config/impl/DefaultTransformer.java b/config/src/main/java/com/typesafe/config/impl/DefaultTransformer.java
index b51ceb252311bff3b74e369ad2ac7ab480107be8..5f1b71774875c4774d77bd1fe0a2bb7b3b957c1f 100644
index b51ceb252311bff3b74e369ad2ac7ab480107be8..a67cbe6ba7ba85f9b92a3ddbdcdc7b44af65963c 100644
--- a/config/src/main/java/com/typesafe/config/impl/DefaultTransformer.java
+++ b/config/src/main/java/com/typesafe/config/impl/DefaultTransformer.java
@@ -6,7 +6,7 @@ package com.typesafe.config.impl;
@@ -4,10 +4,8 @@
package com.typesafe.config.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.TreeMap;

import com.typesafe.config.ConfigValueType;
@@ -89,7 +89,7 @@ final class DefaultTransformer {

@@ -89,7 +87,7 @@ final class DefaultTransformer {
// does not contain any numeric keys. This means we don't allow
// empty objects here though :-/
AbstractConfigObject o = (AbstractConfigObject) value;
- Map<Integer, AbstractConfigValue> values = new HashMap<Integer, AbstractConfigValue>();
+ Map<Integer, AbstractConfigValue> values = new LinkedHashMap<Integer, AbstractConfigValue>();
+ Map<Integer, AbstractConfigValue> values = new TreeMap<>();
for (String key : o.keySet()) {
int i;
try {
@@ -102,21 +100,10 @@ final class DefaultTransformer {
}
}
if (!values.isEmpty()) {
- ArrayList<Map.Entry<Integer, AbstractConfigValue>> entryList = new ArrayList<Map.Entry<Integer, AbstractConfigValue>>(
- values.entrySet());
- // sort by numeric index
- Collections.sort(entryList,
- new Comparator<Map.Entry<Integer, AbstractConfigValue>>() {
- @Override
- public int compare(Map.Entry<Integer, AbstractConfigValue> a,
- Map.Entry<Integer, AbstractConfigValue> b) {
- return Integer.compare(a.getKey(), b.getKey());
- }
- });
// drop the indices (we allow gaps in the indices, for better or
// worse)
ArrayList<AbstractConfigValue> list = new ArrayList<AbstractConfigValue>();
- for (Map.Entry<Integer, AbstractConfigValue> entry : entryList) {
+ for (Map.Entry<Integer, AbstractConfigValue> entry : values.entrySet()) {
list.add(entry.getValue());
}
return new SimpleConfigList(value.origin(), list);
diff --git a/config/src/main/java/com/typesafe/config/impl/PropertiesParser.java b/config/src/main/java/com/typesafe/config/impl/PropertiesParser.java
index ee26a393a9a4a1fa4274a34c5de359559f08864a..4bc4e9b6030c995a5900922202e3442fb5936988 100644
--- a/config/src/main/java/com/typesafe/config/impl/PropertiesParser.java
Expand Down Expand Up @@ -230,16 +221,14 @@ index a208e8a6997f2dc52bc8af774479a2b76986254b..b68ef502d7f89211835ac595c03ea4cb
String key = in.readUTF();
AbstractConfigValue v = readValue(in, origin);
diff --git a/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java b/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java
index 12c0d3f7afa27861d5e83510121b225830f701dc..648298b797a004c1c47049bc90a13c66d16cc05a 100644
index 12c0d3f7afa27861d5e83510121b225830f701dc..b7f3eca33a32df5c926aeb9441d7719eb672c95e 100644
--- a/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java
+++ b/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java
@@ -14,8 +14,8 @@ import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAmount;
@@ -15,7 +15,7 @@ import java.time.temporal.TemporalAmount;
import java.util.AbstractMap;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.HashMap;
-import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
Expand All @@ -253,15 +242,6 @@ index 12c0d3f7afa27861d5e83510121b225830f701dc..648298b797a004c1c47049bc90a13c66
findPaths(entries, null, object);
return entries;
}
@@ -825,7 +825,7 @@ final class SimpleConfig implements Config, MergeableValue, Serializable {
}

private static Map<String, MemoryUnit> makeUnitsMap() {
- Map<String, MemoryUnit> map = new HashMap<String, MemoryUnit>();
+ Map<String, MemoryUnit> map = new LinkedHashMap<String, MemoryUnit>();
for (MemoryUnit unit : MemoryUnit.values()) {
map.put(unit.prefix + "byte", unit);
map.put(unit.prefix + "bytes", unit);
diff --git a/config/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java b/config/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java
index ef69c68855d1a79a874df763d10a761fa36a364d..7dfc361bf126c4583782d8ab1e14bd29c27a39c1 100644
--- a/config/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java
Expand Down

0 comments on commit 3346c6f

Please sign in to comment.