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;
}
protected ImmutableLeafSetNodeBuilder(final ImmutableLeafSetNode<T> node) {
- nodeIdentifier = node.getIdentifier();
+ nodeIdentifier = node.name();
value = MapAdaptor.getDefaultInstance().takeSnapshot(node.children);
}
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;
}
@Override
public ImmutableLeafSetNodeBuilder<T> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
- this.nodeIdentifier = withNodeIdentifier;
+ nodeIdentifier = withNodeIdentifier;
return this;
}
@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;
}
}
}