Disconnect NormalizedNode from Identifiable
[yangtools.git] / data / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableLeafSetNodeBuilder.java
index d034b7f942659476d60aeeb64e7e7221b7740911..61ba04eac555ce761f46e08e7b8ec31b4376e5ce 100644 (file)
@@ -18,11 +18,9 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
 import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
 import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueNode;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 
 public class ImmutableLeafSetNodeBuilder<T> implements ListNodeBuilder<T, SystemLeafSetNode<T>> {
     private static final int DEFAULT_CAPACITY = 4;
@@ -44,7 +42,7 @@ public class ImmutableLeafSetNodeBuilder<T> implements ListNodeBuilder<T, System
     }
 
     protected ImmutableLeafSetNodeBuilder(final ImmutableLeafSetNode<T> node) {
-        nodeIdentifier = node.getIdentifier();
+        nodeIdentifier = node.name();
         value = MapAdaptor.getDefaultInstance().takeSnapshot(node.children);
     }
 
@@ -63,29 +61,15 @@ public class ImmutableLeafSetNodeBuilder<T> implements ListNodeBuilder<T, System
         throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
     }
 
-    @Deprecated(since = "6.0.7", forRemoval = true)
-    public static <T> @NonNull ListNodeBuilder<T, SystemLeafSetNode<T>> create(final LeafListSchemaNode schema) {
-        return new SchemaAwareImmutableLeafSetNodeBuilder<>(schema);
-    }
-
-    @Deprecated(since = "6.0.7", forRemoval = true)
-    public static <T> @NonNull ListNodeBuilder<T, SystemLeafSetNode<T>> create(final LeafListSchemaNode schema,
-            final LeafSetNode<T> node) {
-        if (node instanceof ImmutableLeafSetNode) {
-            return new SchemaAwareImmutableLeafSetNodeBuilder<>(schema, (ImmutableLeafSetNode<T>) node);
-        }
-        throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
-    }
-
     @Override
     public ImmutableLeafSetNodeBuilder<T> withChild(final LeafSetEntryNode<T> child) {
-        this.value.put(child.getIdentifier(), child);
+        value.put(child.name(), child);
         return this;
     }
 
     @Override
     public ImmutableLeafSetNodeBuilder<T> withoutChild(final PathArgument key) {
-        this.value.remove(key);
+        value.remove(key);
         return this;
     }
 
@@ -96,7 +80,7 @@ public class ImmutableLeafSetNodeBuilder<T> implements ListNodeBuilder<T, System
 
     @Override
     public ImmutableLeafSetNodeBuilder<T> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
-        this.nodeIdentifier = withNodeIdentifier;
+        nodeIdentifier = withNodeIdentifier;
         return this;
     }
 
@@ -161,7 +145,18 @@ public class ImmutableLeafSetNodeBuilder<T> implements ListNodeBuilder<T, System
 
         @Override
         protected boolean valueEquals(final SystemLeafSetNode<?> other) {
-            return children.equals(((ImmutableLeafSetNode<?>) other).children);
+            if (other instanceof ImmutableLeafSetNode<?> otherImmutable) {
+                return children.equals(otherImmutable.children);
+            }
+            if (size() != other.size()) {
+                return false;
+            }
+            for (var child : children.values()) {
+                if (!child.equals(other.childByArg(child.name()))) {
+                    return false;
+                }
+            }
+            return true;
         }
     }
 }