Promote ImmutableNodes to yang-data-spi
[yangtools.git] / data / yang-data-spi / src / main / java / org / opendaylight / yangtools / yang / data / spi / node / impl / ImmutableNormalizedNodeMethods.java
diff --git a/data/yang-data-spi/src/main/java/org/opendaylight/yangtools/yang/data/spi/node/impl/ImmutableNormalizedNodeMethods.java b/data/yang-data-spi/src/main/java/org/opendaylight/yangtools/yang/data/spi/node/impl/ImmutableNormalizedNodeMethods.java
new file mode 100644 (file)
index 0000000..0f1648a
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.spi.node.impl;
+
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
+
+/**
+ * Various utility methods for implementing NormalizedNode contracts.
+ */
+final class ImmutableNormalizedNodeMethods {
+    private ImmutableNormalizedNodeMethods() {
+        // Hidden on purpose
+    }
+
+    static boolean bodyEquals(final DataContainerNode thisInstance, final DataContainerNode other) {
+        if (thisInstance.size() != other.size()) {
+            return false;
+        }
+        for (var child : thisInstance.body()) {
+            if (!child.equals(other.childByArg(child.name()))) {
+                return false;
+            }
+        }
+        return true;
+    }
+}