Add schema-aware builders
[yangtools.git] / data / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableUserLeafSetNodeBuilder.java
index dbed22fc10e9917aa8856f7e11fcdc6916221cfa..7c593ecfa50b1302546fe43ed14e49047c7aa872 100644 (file)
@@ -19,21 +19,23 @@ 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.UserLeafSetNode;
 import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
 import org.opendaylight.yangtools.yang.data.spi.node.AbstractNormalizedNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 
-public final class ImmutableUserLeafSetNodeBuilder<T> implements ListNodeBuilder<T, UserLeafSetNode<T>> {
+public class ImmutableUserLeafSetNodeBuilder<T> implements ListNodeBuilder<T, UserLeafSetNode<T>> {
     private Map<NodeWithValue, LeafSetEntryNode<T>> value;
     private NodeIdentifier nodeIdentifier;
     private boolean dirty;
 
-    private ImmutableUserLeafSetNodeBuilder() {
+    ImmutableUserLeafSetNodeBuilder() {
         value = new LinkedHashMap<>();
         dirty = false;
     }
 
-    private ImmutableUserLeafSetNodeBuilder(final ImmutableUserLeafSetNode<T> node) {
+    ImmutableUserLeafSetNodeBuilder(final ImmutableUserLeafSetNode<T> node) {
         nodeIdentifier = node.getIdentifier();
         value = node.getChildren();
         dirty = true;
@@ -52,6 +54,20 @@ public final class ImmutableUserLeafSetNodeBuilder<T> implements ListNodeBuilder
         return new ImmutableUserLeafSetNodeBuilder<>((ImmutableUserLeafSetNode<T>) node);
     }
 
+    @Deprecated(since = "6.0.7", forRemoval = true)
+    public static <T> @NonNull ListNodeBuilder<T, UserLeafSetNode<T>> create(final LeafListSchemaNode schema) {
+        return new SchemaAwareImmutableOrderedLeafSetNodeBuilder<>(schema);
+    }
+
+    @Deprecated(since = "6.0.7", forRemoval = true)
+    public static <T> @NonNull ListNodeBuilder<T, UserLeafSetNode<T>> create(final LeafListSchemaNode schema,
+            final LeafSetNode<T> node) {
+        if (node instanceof ImmutableUserLeafSetNode<?>) {
+            return new SchemaAwareImmutableOrderedLeafSetNodeBuilder<>(schema, (ImmutableUserLeafSetNode<T>) node);
+        }
+        throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
+    }
+
     private void checkDirty() {
         if (dirty) {
             value = new LinkedHashMap<>(value);