Phillippko commented on code in PR #5166:
URL: https://github.com/apache/ignite-3/pull/5166#discussion_r1944117817


##########
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/validation/ConfigurationDuplicatesValidator.java:
##########
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.configuration.validation;
+
+import com.typesafe.config.ConfigParseOptions;
+import com.typesafe.config.impl.Parseable;
+import com.typesafe.config.parser.ConfigDocument;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Queue;
+import java.util.Set;
+import org.apache.ignite.configuration.validation.ValidationIssue;
+import org.jetbrains.annotations.Nullable;
+
+/** Validates that there are no duplicate keys in the configuration. */
+public class ConfigurationDuplicatesValidator {
+    /**
+     * Validates that there are no duplicate keys in the passed configuration.
+     *
+     * @param cfg configuration in HOCON or JSON format.
+     */
+    public static Collection<ValidationIssue> validate(String cfg) {
+        Object root = getConfigRoot(cfg);
+
+        Queue<Node> queue = new ArrayDeque<>();
+        queue.add(new Node(root, new ArrayList<>(), null));
+
+        Set<String> paths = new HashSet<>();
+        Set<ValidationIssue> issues = new HashSet<>();
+
+        while (!queue.isEmpty()) {
+            Node currentNode = queue.poll();
+            List<Object> nodeChildren = 
getChildrenOrEmpty(currentNode.configNode);
+
+            if (nodeChildren.isEmpty()) {
+                continue;
+            }
+
+            Object firstChild = nodeChildren.get(0);
+            ArrayList<String> currentPath = new 
ArrayList<>(currentNode.basePath);
+
+            if (ConfigNodePath.isInstance(firstChild) || currentNode.index != 
null) {

Review Comment:
   Refactored and added a comment
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to