Introduce NormalizedNode.Builder interfaces 99/109399/7
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 21 Dec 2023 11:58:11 +0000 (12:58 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 22 Dec 2023 21:32:07 +0000 (22:32 +0100)
Each valid end-user specialization get a Builder interface, which is
then implemented by a immutable builder.

The hierarchy starts at NormalizedNode.Builder and crosses to the legacy
NormalizedNodeBuilder, ending with, for example, ContainerNode.Builder.

This builder hierarchy allows is to improve Builders API accuracy -- and
that accuracy in turn allows us to disconnect
InterningLeaf(Set)NodeBuilder from the immutable hierarchy, becoming
just forwarding implementations of Leaf(Set)Node.Builder.

JIRA: YANGTOOLS-1259
Change-Id: I8dd84914e7aef66619f6a8dfde9aa76b8aec6538
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
46 files changed:
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/AnydataNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/AnyxmlNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/ChoiceNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/ContainerNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/LeafNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/LeafSetEntryNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/MapEntryNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/NormalizedNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/SystemLeafSetNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/SystemMapNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/UnkeyedListEntryNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/UnkeyedListNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/UserLeafSetNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/UserMapNode.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/builder/NormalizedNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/Builders.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableMetadataNormalizedNodeStreamWriter.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNormalizedNodeStreamWriter.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InterningLeafNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InterningLeafSetNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ReusableImmutableNormalizedNodeStreamWriter.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableAnyXmlNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableAnydataNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableChoiceNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableContainerNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableLeafNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableLeafSetEntryNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableLeafSetNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableMapEntryNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableMapNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableUnkeyedListEntryNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableUnkeyedListNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableUserLeafSetNodeBuilder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableUserMapNodeBuilder.java
data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java
data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java
data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedNodeUtilsTest.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/ChoiceModificationStrategy.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/ContainerModificationStrategy.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/LeafSetModificationStrategy.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/ListModificationStrategy.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/MapEntryModificationStrategy.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/MapModificationStrategy.java
data/yang-data-tree-ri/src/test/java/org/opendaylight/yangtools/yang/data/tree/impl/Bug4454Test.java
data/yang-data-tree-ri/src/test/java/org/opendaylight/yangtools/yang/data/tree/impl/ListConstraintsValidation.java

index c0ff80110316ad11c3d00191c189552deb3716d3..382b01144f6008893b7317c508ca69c0525eb1f1 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.yangtools.yang.data.api.schema;
 
 import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
 
 /**
  * A NormalizedNode holding the contents of an {@code anydata} node in some object model. While no guarantees are placed
@@ -30,4 +32,11 @@ public non-sealed interface AnydataNode<V> extends ForeignDataNode<V> {
     default Class<AnydataNode> contract() {
         return AnydataNode.class;
     }
+
+    /**
+     * A builder of {@link AnydataNode}s.
+     */
+    interface Builder<V> extends NormalizedNodeBuilder<NodeIdentifier, V, AnydataNode<V>> {
+        // Just a specialization
+    }
 }
index e7698fa1d0141b12cd5e0b8917ecd096ac1aaaa8..6c6bd1b062ecf964dc14e576c0f6df4acb2462bb 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.yangtools.yang.data.api.schema;
 
 import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
 
 /**
  * A NormalizedNode holding the contents of an {@code anyxml} node in some object model. This interface is a common
@@ -22,4 +24,11 @@ public non-sealed interface AnyxmlNode<V> extends ForeignDataNode<V> {
     default Class<AnyxmlNode> contract() {
         return AnyxmlNode.class;
     }
+
+    /**
+     * A builder of {@link AnyxmlNode}s.
+     */
+    interface Builder<V, N extends AnyxmlNode<V>> extends NormalizedNodeBuilder<NodeIdentifier, V, N> {
+        // Just a specialization
+    }
 }
index f222fc61281335aa683f0165dd8351cef2759acc..f385de824c620387d0e0941a1fb1f0fa56bea296 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
+
 /**
  * Node representing data instance of <code>choice</code>.
  *
@@ -28,4 +31,11 @@ public non-sealed interface ChoiceNode extends DataContainerNode, DataContainerC
     default Class<ChoiceNode> contract() {
         return ChoiceNode.class;
     }
+
+    /**
+     * A builder of {@link ChoiceNode}s.
+     */
+    interface Builder extends DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> {
+        // Just a specialization
+    }
 }
index 3c2faa11b74e1e92ba3128cbfc1350c276e1f1cd..535b60e43b627c7e6c8b8f369f40cd18015e6fcd 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
+
 /**
  * Data subtree with cardinality 0..1 in the context of parent node.
  *
@@ -22,4 +25,11 @@ public non-sealed interface ContainerNode extends DataContainerNode, DataContain
     default Class<ContainerNode> contract() {
         return ContainerNode.class;
     }
+
+    /**
+     * A builder of {@link ContainerNode}s.
+     */
+    interface Builder extends DataContainerNodeBuilder<NodeIdentifier, ContainerNode> {
+        // Just a specialization
+    }
 }
index 7b01181d6625f3896c3f4346fb2294876afa9fea..c7b9ca238641cb2986044348563d4d69816be9cf 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
+
 /**
  * Leaf node with multiplicity 0..1.
  *
@@ -22,4 +25,11 @@ public non-sealed interface LeafNode<T> extends ValueNode<T>, DataContainerChild
     default Class<LeafNode> contract() {
         return LeafNode.class;
     }
+
+    /**
+     * A builder of {@link LeafNode}s.
+     */
+    interface Builder<V> extends NormalizedNodeBuilder<NodeIdentifier, V, LeafNode<V>> {
+        // Just a specialization
+    }
 }
index 730f17e8a7b9ca498a00acb8a1a1504693adcfee..30d5764a6d1516e362255bea66b2d875eb86073f 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.data.api.schema;
 
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
 
 /**
  * Leaf node with multiplicity 0...n. Leaf node has a value, but no child nodes in the data tree, schema for leaf node
@@ -33,4 +34,11 @@ public non-sealed interface LeafSetEntryNode<T> extends ValueNode<T> {
      */
     @Override
     NodeWithValue<T> name();
+
+    /**
+     * A builder of {@link LeafSetEntryNode}s.
+     */
+    interface Builder<T> extends NormalizedNodeBuilder<NodeWithValue<T>, T, LeafSetEntryNode<T>> {
+        // Just a specialization
+    }
 }
index 6363e0ae7e2dd4742edad34e1d1d3c841d25d9f9..190458aff568c7baf82c0d881d3edfd6ea49bd68 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.yangtools.yang.data.api.schema;
 
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
 
 /**
  * Instance of Map entry, this node does not contains value, but child nodes.
@@ -32,4 +33,11 @@ public interface MapEntryNode extends DataContainerNode {
      */
     @Override
     NodeIdentifierWithPredicates name();
+
+    /**
+     * A builder of {@link MapEntryNode}s.
+     */
+    interface Builder extends DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> {
+        // Just a specialization
+    }
 }
index 2c65912b8a0993bc7555026679ed9753a9d34085..d2ca795bdaf0ad30ce5165f98a21723a0fa25b1c 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.concepts.Mutable;
 import org.opendaylight.yangtools.concepts.PrettyTreeAware;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 
@@ -49,4 +51,17 @@ public interface NormalizedNode extends NormalizedData, PrettyTreeAware {
 
     @Override
     PathArgument name();
+
+    /**
+     * A builder of {@link NormalizedNode}s.
+     */
+    interface Builder extends Mutable {
+        /**
+         * Return a builder {@link NormalizedNode} contract.
+         *
+         * @return a built NormalizedNode
+         * @throws IllegalStateException if this builder does not have sufficient state
+         */
+        @NonNull NormalizedNode build();
+    }
 }
index 667003b24dd3960e11beb0dc2ebdc0af99f3d33c..0b46b45a70b87740bc92eab860193a6557c4bfa5 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
+
 /**
  * {@link LeafSetNode} which does not preserve user-supplied ordering. This node represents a data instance of
  * a {@code leaf-list} without a {@code ordered-by user;} substatement, i.e. when the {@code leaf-list} is effectively
@@ -28,4 +30,11 @@ public non-sealed interface SystemLeafSetNode<T> extends LeafSetNode<T>, Orderin
 
     @Override
     boolean equals(Object obj);
+
+    /**
+     * A builder of {@link SystemLeafSetNode}s.
+     */
+    interface Builder<T> extends ListNodeBuilder<T, SystemLeafSetNode<T>> {
+        // Just a specialization
+    }
 }
index 22410a34158b11b17269a18e8e3d5b2334381276..fec156f1e70a08ef4e45510dd7094cf794c1cf5e 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
+
 /**
  * {@link MapNode} which additionally preserves user-supplied ordering. This node represents a data instance of
  * a {@code list} with {@code ordered-by user;} substatement and a {@code key} definition.
@@ -22,4 +24,11 @@ public non-sealed interface SystemMapNode extends MapNode, OrderingAware.System
 
     @Override
     boolean equals(Object obj);
+
+    /**
+     * A builder of {@link SystemMapNode}s.
+     */
+    interface Builder extends CollectionNodeBuilder<MapEntryNode, SystemMapNode> {
+        // Just a specialization
+    }
 }
index c36344730fc7206f5f9a65293bfd68780c32f41b..80594f2a441d296f77593110f7810f35eeb35e57 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.data.api.schema;
 
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
 
 /**
  * List entry node, which does not have value, but child nodes. Represents an instance of data, which schema is instance
@@ -25,4 +26,11 @@ public interface UnkeyedListEntryNode extends DataContainerNode {
 
     @Override
     NodeIdentifier name();
+
+    /**
+     * A builder of {@link UnkeyedListNode}s.
+     */
+    interface Builder extends DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> {
+        // Just a specialization
+    }
 }
index ec86b01fc6f572bf04e9b51bbb7a121a4aa2c0d7..63230f0b59fbdea8646fdafa8bca1b6256784695 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
+
 /**
  * Containment node, which contains {@link UnkeyedListEntryNode} of the same type, which may be quickly retrieved using
  * key. This node maps to the <code>list</code> statement in YANG schema, which did not define {@code key} substatement.
@@ -21,4 +23,11 @@ public non-sealed interface UnkeyedListNode
     default Class<UnkeyedListNode> contract() {
         return UnkeyedListNode.class;
     }
+
+    /**
+     * A builder of {@link UnkeyedListNode}s.
+     */
+    interface Builder extends CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> {
+        // Just a specialization
+    }
 }
index 2814cd7eb9aea49ebe809bcc82c751fe2962c9a9..fd8556bc9bc7c5111c749c3598d6c41838657798 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
+
 /**
  * {@link LeafSetNode} which preserves user-supplied ordering. This node represents a data instance of
  * a {@code leaf-list} with a {@code ordered-by user;} substatement.
@@ -19,4 +21,11 @@ public non-sealed interface UserLeafSetNode<T> extends LeafSetNode<T>, OrderedNo
     default Class<UserLeafSetNode> contract() {
         return UserLeafSetNode.class;
     }
+
+    /**
+     * A builder of {@link UserLeafSetNode}s.
+     */
+    interface Builder<T> extends ListNodeBuilder<T, UserLeafSetNode<T>> {
+        // Just a specialization
+    }
 }
index 9dfb58467481d1c6cacf010853603f341c6f206a..da71d77fdd9a32f5865636814ffcf3a74251c000 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.yangtools.yang.data.api.schema;
 
 import java.util.Map;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
 
 /**
  * {@link MapNode} which additionally preserves user-supplied ordering. This node represents a data instance of
@@ -28,4 +29,11 @@ public non-sealed interface UserMapNode extends MapNode, OrderedNodeContainer<Ma
      */
     @Override
     Map<NodeIdentifierWithPredicates, MapEntryNode> asMap();
+
+    /**
+     * A builder of {@link UserMapNode}s.
+     */
+    interface Builder extends CollectionNodeBuilder<MapEntryNode, UserMapNode> {
+        // Just a specialization
+    }
 }
index d6ed91cea2084dbe9ca33d30bb98f612c0160352..5097b420268dc5edb53a6465007e70a48069a46f 100644 (file)
@@ -9,22 +9,18 @@ package org.opendaylight.yangtools.yang.data.api.schema.builder;
 
 import com.google.common.annotations.Beta;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.Mutable;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 @Beta
-public interface NormalizedNodeBuilder<I extends PathArgument, V, R extends NormalizedNode> extends Mutable {
+// FIXME: YANGTOOLS-1259: eliminate this interface
+public interface NormalizedNodeBuilder<I extends PathArgument, V, R extends NormalizedNode>
+        extends NormalizedNode.Builder {
 
     @NonNull NormalizedNodeBuilder<I, V, R> withValue(V value);
 
     @NonNull NormalizedNodeBuilder<I, V, R> withNodeIdentifier(I nodeIdentifier);
 
-    /**
-     * Return an implementation of the {@link R} NormalizedNode contract.
-     *
-     * @return A built NormalizedNode
-     * @throws IllegalStateException if this builder does not have sufficient state
-     */
-    @NonNull R build();
+    @Override
+    R build();
 }
index 2063f1291a73ce1803b690cc1537cad33478b5d5..393fd7440128d36178881e3eb1e9f1b4ffe1cd40 100644 (file)
@@ -8,10 +8,9 @@
 package org.opendaylight.yangtools.yang.data.impl.schema;
 
 import javax.xml.transform.dom.DOMSource;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.schema.AnydataNode;
+import org.opendaylight.yangtools.yang.data.api.schema.AnyxmlNode;
 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
@@ -24,10 +23,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
 import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
 import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAnyXmlNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAnydataNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder;
@@ -47,113 +42,107 @@ public final class Builders {
         // Hidden on purpose
     }
 
-    public static <T> NormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> leafBuilder() {
-        return ImmutableLeafNodeBuilder.create();
+    public static <T> LeafNode.@NonNull Builder<T> leafBuilder() {
+        return new ImmutableLeafNodeBuilder<>();
     }
 
-    // FIXME: 7.0.0: add generic arguments
-    public static <T> NormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> leafSetEntryBuilder() {
-        return ImmutableLeafSetEntryNodeBuilder.create();
+    public static <T> LeafSetEntryNode.@NonNull Builder<T> leafSetEntryBuilder() {
+        return new ImmutableLeafSetEntryNodeBuilder<>();
     }
 
-    public static NormalizedNodeBuilder<NodeIdentifier, DOMSource, DOMSourceAnyxmlNode> anyXmlBuilder() {
-        return ImmutableAnyXmlNodeBuilder.create();
+    public static AnyxmlNode.@NonNull Builder<DOMSource, DOMSourceAnyxmlNode> anyXmlBuilder() {
+        return new ImmutableAnyXmlNodeBuilder();
     }
 
-    public static <T> NormalizedNodeBuilder<NodeIdentifier, T, AnydataNode<T>> anydataBuilder(
-            final Class<T> objectModel) {
-        return ImmutableAnydataNodeBuilder.create(objectModel);
+    public static <T> AnydataNode.@NonNull Builder<T> anydataBuilder(final Class<T> objectModel) {
+        return new ImmutableAnydataNodeBuilder<>(objectModel);
     }
 
-    public static <T> ListNodeBuilder<T, UserLeafSetNode<T>> orderedLeafSetBuilder() {
-        return ImmutableUserLeafSetNodeBuilder.create();
+    public static <T> UserLeafSetNode.@NonNull Builder<T> orderedLeafSetBuilder() {
+        return new ImmutableUserLeafSetNodeBuilder<>();
     }
 
-    public static <T> ListNodeBuilder<T, UserLeafSetNode<T>> orderedLeafSetBuilder(final UserLeafSetNode<T> node) {
+    public static <T> UserLeafSetNode.@NonNull Builder<T> orderedLeafSetBuilder(final UserLeafSetNode<T> node) {
         return ImmutableUserLeafSetNodeBuilder.create(node);
     }
 
-    public static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> leafSetBuilder() {
-        return ImmutableLeafSetNodeBuilder.create();
+    public static <T> SystemLeafSetNode.@NonNull Builder<T> leafSetBuilder() {
+        return new ImmutableLeafSetNodeBuilder<>();
     }
 
-    public static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> leafSetBuilder(final SystemLeafSetNode<T> node) {
+    public static <T> SystemLeafSetNode.@NonNull Builder<T> leafSetBuilder(final int sizeHint) {
+        return new ImmutableLeafSetNodeBuilder<>(sizeHint);
+    }
+
+    public static <T> SystemLeafSetNode.@NonNull Builder<T> leafSetBuilder(final SystemLeafSetNode<T> node) {
         return ImmutableLeafSetNodeBuilder.create(node);
     }
 
-    public static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> leafSetBuilder(final int sizeHint) {
-        return ImmutableLeafSetNodeBuilder.create(sizeHint);
+    public static ContainerNode.@NonNull Builder containerBuilder() {
+        return new ImmutableContainerNodeBuilder();
     }
 
-    public static DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder() {
-        return ImmutableContainerNodeBuilder.create();
+    public static ContainerNode.@NonNull Builder containerBuilder(final int sizeHint) {
+        return new ImmutableContainerNodeBuilder(sizeHint);
     }
 
-    public static DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder(
-            final ContainerNode node) {
+    public static ContainerNode.@NonNull Builder containerBuilder(final ContainerNode node) {
         return ImmutableContainerNodeBuilder.create(node);
     }
 
-    public static DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder(final int sizeHint) {
-        return ImmutableContainerNodeBuilder.create(sizeHint);
+    public static MapEntryNode.@NonNull Builder mapEntryBuilder() {
+        return new ImmutableMapEntryNodeBuilder();
     }
 
-    public static DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder() {
-        return ImmutableMapEntryNodeBuilder.create();
+    public static MapEntryNode.@NonNull Builder mapEntryBuilder(final int sizeHint) {
+        return new ImmutableMapEntryNodeBuilder(sizeHint);
     }
 
-    public static DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder(
-            final MapEntryNode mapEntryNode) {
+    public static MapEntryNode.@NonNull Builder mapEntryBuilder(final MapEntryNode mapEntryNode) {
         return ImmutableMapEntryNodeBuilder.create(mapEntryNode);
     }
 
-    public static DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder(
-            final int sizeHint) {
-        return ImmutableMapEntryNodeBuilder.create(sizeHint);
+    public static UserMapNode.@NonNull Builder orderedMapBuilder() {
+        return new ImmutableUserMapNodeBuilder();
     }
 
-    public static CollectionNodeBuilder<MapEntryNode, UserMapNode> orderedMapBuilder() {
-        return ImmutableUserMapNodeBuilder.create();
+    public static UserMapNode.@NonNull Builder orderedMapBuilder(final int sizeHint) {
+        return new ImmutableUserMapNodeBuilder(sizeHint);
     }
 
-    public static CollectionNodeBuilder<MapEntryNode, UserMapNode> orderedMapBuilder(final int sizeHint) {
-        return ImmutableUserMapNodeBuilder.create(sizeHint);
+    public static UnkeyedListNode.@NonNull Builder unkeyedListBuilder() {
+        return new ImmutableUnkeyedListNodeBuilder();
     }
 
-    public static CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> unkeyedListBuilder() {
-        return ImmutableUnkeyedListNodeBuilder.create();
+    public static UnkeyedListNode.@NonNull Builder unkeyedListBuilder(final int sizeHint) {
+        return new ImmutableUnkeyedListNodeBuilder(sizeHint);
     }
 
-    public static CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> unkeyedListBuilder(final int sizeHint) {
-        return ImmutableUnkeyedListNodeBuilder.create(sizeHint);
+    public static SystemMapNode.@NonNull Builder mapBuilder() {
+        return new ImmutableMapNodeBuilder();
     }
 
-    public static CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder() {
-        return ImmutableMapNodeBuilder.create();
+    public static SystemMapNode.@NonNull Builder mapBuilder(final int sizeHint) {
+        return new ImmutableMapNodeBuilder(sizeHint);
     }
 
-    public static CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder(final SystemMapNode node) {
+    public static SystemMapNode.@NonNull Builder mapBuilder(final SystemMapNode node) {
         return ImmutableMapNodeBuilder.create(node);
     }
 
-    public static CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder(final int sizeHint) {
-        return ImmutableMapNodeBuilder.create(sizeHint);
-    }
-
-    public static DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder() {
-        return ImmutableChoiceNodeBuilder.create();
+    public static ChoiceNode.@NonNull Builder choiceBuilder() {
+        return new ImmutableChoiceNodeBuilder();
     }
 
-    public static DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder(final int sizeHint) {
-        return ImmutableChoiceNodeBuilder.create(sizeHint);
+    public static ChoiceNode.@NonNull Builder choiceBuilder(final int sizeHint) {
+        return new ImmutableChoiceNodeBuilder(sizeHint);
     }
 
-    public static DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> unkeyedListEntryBuilder() {
-        return ImmutableUnkeyedListEntryNodeBuilder.create();
+    public static UnkeyedListEntryNode.@NonNull Builder unkeyedListEntryBuilder() {
+        return new ImmutableUnkeyedListEntryNodeBuilder();
     }
 
-    public static DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> unkeyedListEntryBuilder(
-            final int sizeHint) {
-        return ImmutableUnkeyedListEntryNodeBuilder.create(sizeHint);
+    public static UnkeyedListEntryNode.@NonNull Builder unkeyedListEntryBuilder(final int sizeHint) {
+        return new ImmutableUnkeyedListEntryNodeBuilder(sizeHint);
     }
 }
index 0e2bc22fcefe43d9ab29c5babd2af030d6184db9..69ff51bebea3268de6b4ff0b213620013acbaf1d 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedMetadata;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter.MetadataExtension;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedMetadata.Builder;
@@ -37,14 +38,14 @@ public class ImmutableMetadataNormalizedNodeStreamWriter extends ImmutableNormal
      */
     public static final class State {
         final BuilderEntry metaBuilder;
-        final NormalizedNodeBuilder dataBuilder;
+        final NormalizedNode.Builder dataBuilder;
 
-        State(final NormalizedNodeBuilder dataBuilder, final BuilderEntry metadataBuilder) {
+        State(final NormalizedNode.Builder dataBuilder, final BuilderEntry metadataBuilder) {
             this.dataBuilder = requireNonNull(dataBuilder);
             metaBuilder = requireNonNull(metadataBuilder);
         }
 
-        public NormalizedNodeBuilder getDataBuilder() {
+        public NormalizedNode.Builder getDataBuilder() {
             return dataBuilder;
         }
 
index 20aee41442da6eae3892e7e80755f5487958fcb6..1029849797e033beed713a7bc5d91cb354f5d1f7 100644 (file)
@@ -22,8 +22,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
 import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.YangInstanceIdentifierWriter;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
@@ -37,17 +35,19 @@ public final class ImmutableNodes {
         // Hidden on purpose
     }
 
-    public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapNodeBuilder() {
+    public static SystemMapNode.@NonNull Builder mapNodeBuilder() {
         return Builders.mapBuilder();
     }
 
-    public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapNodeBuilder(final QName name) {
+    public static SystemMapNode.@NonNull Builder mapNodeBuilder(final QName name) {
         return mapNodeBuilder(NodeIdentifier.create(name));
     }
 
-    public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapNodeBuilder(
-            final NodeIdentifier name) {
-        return Builders.mapBuilder().withNodeIdentifier(name);
+    public static SystemMapNode.@NonNull Builder mapNodeBuilder(final NodeIdentifier name) {
+        final var ret = Builders.mapBuilder();
+        // FIXME: use fluent once we have specialized enough
+        ret.withNodeIdentifier(name);
+        return ret;
     }
 
     /**
@@ -114,14 +114,17 @@ public final class ImmutableNodes {
         return leafNode(NodeIdentifier.create(name), value);
     }
 
-    public static @NonNull DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder(
-            final QName nodeName, final QName keyName, final Object keyValue) {
-        return Builders.mapEntryBuilder()
-                .withNodeIdentifier(NodeIdentifierWithPredicates.of(nodeName, keyName, keyValue))
-                .withChild(leafNode(keyName, keyValue));
+    public static MapEntryNode.@NonNull Builder mapEntryBuilder(final QName nodeName, final QName keyName,
+            final Object keyValue) {
+        final var ret = Builders.mapEntryBuilder();
+        // FIXME: use fluent once we have specialized enough
+        ret.withNodeIdentifier(NodeIdentifierWithPredicates.of(nodeName, keyName, keyValue))
+            .withChild(leafNode(keyName, keyValue));
+        return ret;
+
     }
 
-    public static @NonNull DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder() {
+    public static MapEntryNode.@NonNull Builder mapEntryBuilder() {
         return Builders.mapEntryBuilder();
     }
 
index 3ec51ae71a8ae813b9710131073ee907ec3f09c2..9ed27e2729c984ae64f18dd8f1e39f5fc92de1a1 100644 (file)
@@ -20,19 +20,21 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 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.LeafNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
 import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeBuilder;
+import org.opendaylight.yangtools.yang.data.util.LeafInterner;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 
 /**
  * Implementation of {@link NormalizedNodeStreamWriter}, which constructs immutable instances of
@@ -50,13 +52,11 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
  * This class is not final for purposes of customization, normal users should not need to subclass it.
  */
 public class ImmutableNormalizedNodeStreamWriter implements NormalizedNodeStreamWriter {
-    @SuppressWarnings("rawtypes")
-    private final Deque<NormalizedNodeBuilder> builders = new ArrayDeque<>();
+    private final Deque<NormalizedNode.Builder> builders = new ArrayDeque<>();
 
     private DataSchemaNode nextSchema;
 
-    @SuppressWarnings("rawtypes")
-    protected ImmutableNormalizedNodeStreamWriter(final NormalizedNodeBuilder topLevelBuilder) {
+    protected ImmutableNormalizedNodeStreamWriter(final NormalizedNode.Builder topLevelBuilder) {
         builders.push(topLevelBuilder);
     }
 
@@ -117,7 +117,7 @@ public class ImmutableNormalizedNodeStreamWriter implements NormalizedNodeStream
 
     @Override
     public void startLeafSetEntryNode(final NodeWithValue<?> name) {
-        final NormalizedNodeBuilder<?, ?, ?> current = current();
+        final var current = current();
         checkArgument(current instanceof ImmutableLeafSetNodeBuilder
             || current instanceof ImmutableUserLeafSetNodeBuilder || current instanceof NormalizationResultBuilder,
             "LeafSetEntryNode is not valid for parent %s", current);
@@ -158,7 +158,7 @@ public class ImmutableNormalizedNodeStreamWriter implements NormalizedNodeStream
 
     @Override
     public void startUnkeyedListItem(final NodeIdentifier name, final int childSizeHint) {
-        final NormalizedNodeBuilder<?, ?, ?> current = current();
+        final var current = current();
         checkArgument(current instanceof ImmutableUnkeyedListNodeBuilder
             || current instanceof NormalizationResultBuilder);
         enter(name, UNKNOWN_SIZE == childSizeHint ? Builders.unkeyedListEntryBuilder()
@@ -173,7 +173,7 @@ public class ImmutableNormalizedNodeStreamWriter implements NormalizedNodeStream
 
     @Override
     public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint) {
-        final NormalizedNodeBuilder<?, ?, ?> current = current();
+        final var current = current();
         checkArgument(current instanceof ImmutableMapNodeBuilder || current instanceof ImmutableUserMapNodeBuilder
             || current instanceof NormalizationResultBuilder);
 
@@ -211,20 +211,22 @@ public class ImmutableNormalizedNodeStreamWriter implements NormalizedNodeStream
 
     @Override
     public void scalarValue(final Object value) {
+        // FIXME: tighten to concrete NormalizedNode.Builder interfaces
         currentScalar().withValue(value);
     }
 
     @Override
     public void domSourceValue(final DOMSource value) {
+        // FIXME: tighten to concrete NormalizedNode.Builder interfaces
         currentScalar().withValue(value);
     }
 
     @Override
     @SuppressWarnings("rawtypes")
     public void endNode() {
-        final NormalizedNodeBuilder finishedBuilder = builders.poll();
+        final var finishedBuilder = builders.poll();
         checkState(finishedBuilder != null, "Node which should be closed does not exists.");
-        final NormalizedNode product = finishedBuilder.build();
+        final var product = finishedBuilder.build();
         nextSchema = null;
 
         writeChild(product);
@@ -260,7 +262,7 @@ public class ImmutableNormalizedNodeStreamWriter implements NormalizedNodeStream
     }
 
     // Exposed for ImmutableMetadataNormalizedNodeStreamWriter
-    protected final NormalizedNodeBuilder popBuilder() {
+    protected final NormalizedNode.Builder popBuilder() {
         return builders.pop();
     }
 
@@ -270,17 +272,23 @@ public class ImmutableNormalizedNodeStreamWriter implements NormalizedNodeStream
         builders.push(builder);
     }
 
-    private <T> ImmutableLeafNodeBuilder<T> leafNodeBuilder(final DataSchemaNode schema) {
-        final InterningLeafNodeBuilder<T> interning = InterningLeafNodeBuilder.forSchema(schema);
-        return interning != null ? interning : leafNodeBuilder();
+    private <T> LeafNode.Builder<T> leafNodeBuilder(final DataSchemaNode schema) {
+        final var builder = this.<T>leafNodeBuilder();
+        if (schema instanceof LeafSchemaNode leafSchema) {
+            final var interner = LeafInterner.<LeafNode<T>>forSchema(leafSchema);
+            if (interner.isPresent()) {
+                return new InterningLeafNodeBuilder<>(builder, interner.orElseThrow());
+            }
+        }
+        return builder;
     }
 
-    <T> ImmutableLeafNodeBuilder<T> leafNodeBuilder() {
-        return new ImmutableLeafNodeBuilder<>();
+    <T> LeafNode.@NonNull Builder<T> leafNodeBuilder() {
+        return Builders.leafBuilder();
     }
 
-    <T> ImmutableLeafSetEntryNodeBuilder<T> leafsetEntryNodeBuilder() {
-        return ImmutableLeafSetEntryNodeBuilder.create();
+    <T> LeafSetEntryNode.@NonNull Builder<T> leafsetEntryNodeBuilder() {
+        return Builders.leafSetEntryBuilder();
     }
 
     private void checkDataNodeContainer() {
@@ -291,25 +299,31 @@ public class ImmutableNormalizedNodeStreamWriter implements NormalizedNodeStream
         }
     }
 
-    @SuppressWarnings("rawtypes")
-    private NormalizedNodeBuilder current() {
+    private NormalizedNode.Builder current() {
         return builders.peek();
     }
 
     @SuppressWarnings("rawtypes")
     private NormalizedNodeContainerBuilder currentContainer() {
-        final NormalizedNodeBuilder current = current();
-        if (current == null) {
-            return null;
+        final var current = current();
+        if (current instanceof NormalizedNodeContainerBuilder builder) {
+            return builder;
         }
-        checkState(current instanceof NormalizedNodeContainerBuilder, "%s is not a node container", current);
-        return (NormalizedNodeContainerBuilder) current;
+        if (current != null) {
+            throw new IllegalStateException(current + " is not a node container");
+        }
+        return null;
     }
 
     @SuppressWarnings("rawtypes")
     private NormalizedNodeBuilder currentScalar() {
-        final NormalizedNodeBuilder current = current();
-        checkState(!(current instanceof NormalizedNodeContainerBuilder), "Unexpected node container %s", current);
-        return current;
+        final var current = current();
+        if (current instanceof NormalizedNodeContainerBuilder) {
+            throw new IllegalStateException("Unexpected node container " + current);
+        }
+        if (current instanceof NormalizedNodeBuilder builder) {
+            return builder;
+        }
+        throw new IllegalStateException("Unexpected non-scalar " + current);
     }
 }
index f415899f7e55c77771898ac8870efe2590aa2529..1224db884213d3e62690ae702441f4c359e6320b 100644 (file)
@@ -10,33 +10,32 @@ package org.opendaylight.yangtools.yang.data.impl.schema;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.collect.Interner;
-import java.util.Optional;
-import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
-import org.opendaylight.yangtools.yang.data.util.LeafInterner;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 
-final class InterningLeafNodeBuilder<T> extends ImmutableLeafNodeBuilder<T> {
+final class InterningLeafNodeBuilder<T> implements LeafNode.Builder<T> {
     private final Interner<LeafNode<T>> interner;
+    private final LeafNode.Builder<T> delegate;
 
-    private InterningLeafNodeBuilder(final Interner<LeafNode<T>> interner) {
+    InterningLeafNodeBuilder(final LeafNode.Builder<T> delegate, final Interner<LeafNode<T>> interner) {
+        this.delegate = requireNonNull(delegate);
         this.interner = requireNonNull(interner);
     }
 
-    static <T> @Nullable InterningLeafNodeBuilder<T> forSchema(final @Nullable DataSchemaNode schema) {
-        if (schema instanceof LeafSchemaNode leafSchema) {
-            final Optional<Interner<LeafNode<T>>> interner = LeafInterner.forSchema(leafSchema);
-            if (interner.isPresent()) {
-                return new InterningLeafNodeBuilder<>(interner.orElseThrow());
-            }
-        }
-        return null;
+    @Override
+    public LeafNode.Builder<T> withValue(final T value) {
+        delegate.withValue(value);
+        return this;
+    }
+
+    @Override
+    public LeafNode.Builder<T> withNodeIdentifier(final NodeIdentifier nodeIdentifier) {
+        delegate.withNodeIdentifier(nodeIdentifier);
+        return this;
     }
 
     @Override
     public LeafNode<T> build() {
-        return interner.intern(super.build());
+        return interner.intern(delegate.build());
     }
 }
index 82c29a3bbc5b4e46664ca7b19624c6263e8bd69e..b8ff2492c9995ed6762cd320ce3f0eb9ceb97a59 100644 (file)
@@ -9,24 +9,25 @@ package org.opendaylight.yangtools.yang.data.impl.schema;
 
 import static java.util.Objects.requireNonNull;
 
+import java.util.Collection;
 import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+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.SystemLeafSetNode;
 import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder;
 import org.opendaylight.yangtools.yang.data.util.LeafsetEntryInterner;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 
-final class InterningLeafSetNodeBuilder<T> extends ImmutableLeafSetNodeBuilder<T> {
+final class InterningLeafSetNodeBuilder<T> implements SystemLeafSetNode.Builder<T> {
+    private final SystemLeafSetNode.Builder<T> delegate;
     private final LeafsetEntryInterner interner;
 
-    private InterningLeafSetNodeBuilder(final LeafsetEntryInterner interner) {
-        this.interner = requireNonNull(interner);
-    }
-
-    private InterningLeafSetNodeBuilder(final LeafsetEntryInterner interner, final int sizeHint) {
-        super(sizeHint);
+    private InterningLeafSetNodeBuilder(final SystemLeafSetNode.Builder<T> delegate,
+            final LeafsetEntryInterner interner) {
+        this.delegate = requireNonNull(delegate);
         this.interner = requireNonNull(interner);
     }
 
@@ -36,26 +37,59 @@ final class InterningLeafSetNodeBuilder<T> extends ImmutableLeafSetNodeBuilder<T
     }
 
     static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> create(final @Nullable DataSchemaNode schema) {
-        final LeafsetEntryInterner interner = getInterner(schema);
-        if (interner != null) {
-            return new InterningLeafSetNodeBuilder<>(interner);
-        }
-
-        return ImmutableLeafSetNodeBuilder.create();
+        final var delegate = Builders.<T>leafSetBuilder();
+        final var interner = getInterner(schema);
+        return interner == null ? delegate : new InterningLeafSetNodeBuilder<>(delegate, interner);
     }
 
     static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> create(final @Nullable DataSchemaNode schema,
             final int sizeHint) {
-        final LeafsetEntryInterner interner = getInterner(schema);
-        if (interner != null) {
-            return new InterningLeafSetNodeBuilder<>(interner, sizeHint);
-        }
+        final var delegate = Builders.<T>leafSetBuilder(sizeHint);
+        final var interner = getInterner(schema);
+        return interner == null ? delegate : new InterningLeafSetNodeBuilder<>(delegate, interner);
+    }
+
+    @Override
+    public ListNodeBuilder<T, SystemLeafSetNode<T>> withNodeIdentifier(final NodeIdentifier nodeIdentifier) {
+        return delegate.withNodeIdentifier(nodeIdentifier);
+    }
+
+    @Override
+    public ListNodeBuilder<T, SystemLeafSetNode<T>> withValue(final Collection<LeafSetEntryNode<T>> value) {
+        // FIXME: pass through interner
+        return delegate.withValue(value);
+    }
+
+    @Override
+    public ListNodeBuilder<T, SystemLeafSetNode<T>> withChild(final LeafSetEntryNode<T> child) {
+        return delegate.withChild(interner.intern(child));
+    }
+
+    @Override
+    public ListNodeBuilder<T, SystemLeafSetNode<T>> withoutChild(final PathArgument key) {
+        return delegate.withoutChild(key);
+    }
+
+    @Override
+    public ListNodeBuilder<T, SystemLeafSetNode<T>> withChildValue(final T child) {
+        // TODO Auto-generated method stub
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, LeafSetEntryNode<T>, SystemLeafSetNode<T>>
+            addChild(final LeafSetEntryNode<T> child) {
+        return withChild(child);
+    }
 
-        return ImmutableLeafSetNodeBuilder.create(sizeHint);
+    @Override
+    public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, LeafSetEntryNode<T>, SystemLeafSetNode<T>>
+            removeChild(final PathArgument key) {
+        return withoutChild(key);
     }
 
     @Override
-    public ImmutableLeafSetNodeBuilder<T> withChild(final LeafSetEntryNode<T> child) {
-        return super.withChild(interner.intern(child));
+    public SystemLeafSetNode<T> build() {
+        return delegate.build();
     }
 }
index ba4f2725087f73fe1512ca0a05953e4db87aced6..f558ae1930567d663fd979c9393ddeb1bad60b65 100644 (file)
@@ -25,7 +25,7 @@ public final class ReusableImmutableNormalizedNodeStreamWriter extends Immutable
         implements ReusableStreamReceiver {
     private final NormalizationResultBuilder builder;
 
-    private final ImmutableLeafSetEntryNodeBuilder<?> leafsetEntryBuilder = ImmutableLeafSetEntryNodeBuilder.create();
+    private final ImmutableLeafSetEntryNodeBuilder<?> leafsetEntryBuilder = new ImmutableLeafSetEntryNodeBuilder<>();
     private final ImmutableLeafNodeBuilder<?> leafNodeBuilder = new ImmutableLeafNodeBuilder<>();
 
     private ReusableImmutableNormalizedNodeStreamWriter(final NormalizationResultBuilder builder) {
index 6c27e99c2088b5a3bf01d1dd51067808a74d0a19..41b41114491256008cc817464a2cdd8a39f943e8 100644 (file)
@@ -8,19 +8,14 @@
 package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
 
 import javax.xml.transform.dom.DOMSource;
-import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.AnyxmlNode;
 import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedSimpleValueNode;
 
-public class ImmutableAnyXmlNodeBuilder
-        extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, DOMSource, DOMSourceAnyxmlNode> {
-
-    public static @NonNull NormalizedNodeBuilder<NodeIdentifier, DOMSource, DOMSourceAnyxmlNode> create() {
-        return new ImmutableAnyXmlNodeBuilder();
-    }
-
+public final class ImmutableAnyXmlNodeBuilder
+        extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, DOMSource, DOMSourceAnyxmlNode>
+        implements AnyxmlNode.Builder<DOMSource, DOMSourceAnyxmlNode> {
     @Override
     public ImmutableAnyXmlNodeBuilder withValue(final DOMSource withValue) {
         super.withValue(withValue);
index 6a604a06a24eb9f493633051183c2a5b86cee640..6beeb32c699ed358680484afcac5b28a50ac39fb 100644 (file)
@@ -13,22 +13,18 @@ import com.google.common.annotations.Beta;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AnydataNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedSimpleValueNode;
 
 @Beta
-public class ImmutableAnydataNodeBuilder<V>
-        extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, V, AnydataNode<V>> {
+public final class ImmutableAnydataNodeBuilder<V>
+        extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, V, AnydataNode<V>>
+        implements AnydataNode.Builder<V> {
     private final @NonNull Class<V> objectModel;
 
-    ImmutableAnydataNodeBuilder(final Class<V> objectModel) {
+    public ImmutableAnydataNodeBuilder(final Class<V> objectModel) {
         this.objectModel = requireNonNull(objectModel);
     }
 
-    public static <V> NormalizedNodeBuilder<NodeIdentifier, V, AnydataNode<V>> create(final Class<V> objectModel) {
-        return new ImmutableAnydataNodeBuilder<>(objectModel);
-    }
-
     @Override
     public AnydataNode<V> build() {
         return new ImmutableAnydataNode<>(getNodeIdentifier(), getValue(), objectModel);
index 7de8f15c4db7f9365845240cb1e32abe49052206..5edf9d5b1099b1010738944e83f90aa3d0d1f960 100644 (file)
@@ -11,35 +11,28 @@ import java.util.Map;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerNode;
 
-public class ImmutableChoiceNodeBuilder extends AbstractImmutableDataContainerNodeBuilder<NodeIdentifier, ChoiceNode> {
-    protected ImmutableChoiceNodeBuilder() {
+public final class ImmutableChoiceNodeBuilder
+        extends AbstractImmutableDataContainerNodeBuilder<NodeIdentifier, ChoiceNode>
+        implements ChoiceNode.Builder {
+    public ImmutableChoiceNodeBuilder() {
 
     }
 
-    protected ImmutableChoiceNodeBuilder(final int sizeHint) {
+    public ImmutableChoiceNodeBuilder(final int sizeHint) {
         super(sizeHint);
     }
 
-    protected ImmutableChoiceNodeBuilder(final ImmutableChoiceNode node) {
+    private ImmutableChoiceNodeBuilder(final ImmutableChoiceNode node) {
         super(node);
     }
 
-    public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> create() {
-        return new ImmutableChoiceNodeBuilder();
-    }
-
-    public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> create(final int sizeHint) {
-        return new ImmutableChoiceNodeBuilder(sizeHint);
-    }
-
-    public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> create(final ChoiceNode node) {
-        if (!(node instanceof ImmutableChoiceNode immutableNode)) {
-            throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
+    public static ChoiceNode.@NonNull Builder create(final ChoiceNode node) {
+        if (node instanceof ImmutableChoiceNode immutableNode) {
+            return new ImmutableChoiceNodeBuilder(immutableNode);
         }
-        return new ImmutableChoiceNodeBuilder(immutableNode);
+        throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
     }
 
     @Override
index 5f4ea979d196f7f038592961f58b59f89672452e..076a466458990bde548552b28dac36ebdf8238f3 100644 (file)
@@ -11,36 +11,28 @@ import java.util.Map;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerNode;
 
-public class ImmutableContainerNodeBuilder
-        extends AbstractImmutableDataContainerNodeBuilder<NodeIdentifier, ContainerNode> {
-    protected ImmutableContainerNodeBuilder() {
+public final class ImmutableContainerNodeBuilder
+        extends AbstractImmutableDataContainerNodeBuilder<NodeIdentifier, ContainerNode>
+        implements ContainerNode.Builder {
+    public ImmutableContainerNodeBuilder() {
 
     }
 
-    protected ImmutableContainerNodeBuilder(final int sizeHint) {
+    public ImmutableContainerNodeBuilder(final int sizeHint) {
         super(sizeHint);
     }
 
-    protected ImmutableContainerNodeBuilder(final ImmutableContainerNode node) {
+    private ImmutableContainerNodeBuilder(final ImmutableContainerNode node) {
         super(node);
     }
 
-    public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create() {
-        return new ImmutableContainerNodeBuilder();
-    }
-
-    public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(final int sizeHint) {
-        return new ImmutableContainerNodeBuilder(sizeHint);
-    }
-
-    public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(final ContainerNode node) {
-        if (!(node instanceof ImmutableContainerNode immutableNode)) {
-            throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
+    public static ContainerNode.@NonNull Builder create(final ContainerNode node) {
+        if (node instanceof ImmutableContainerNode immutableNode) {
+            return new ImmutableContainerNodeBuilder(immutableNode);
         }
-        return new ImmutableContainerNodeBuilder(immutableNode);
+        throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
     }
 
     @Override
index fb6ac333208117c37c2f4b23916c62ad21958664..57f9b749ddc9d2067227272a4c862219cdff0918 100644 (file)
@@ -11,16 +11,11 @@ import com.google.common.annotations.Beta;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedSimpleValueNode;
 
-public class ImmutableLeafNodeBuilder<T>
-        extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> {
-
-    public static <T> @NonNull NormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> create() {
-        return new ImmutableLeafNodeBuilder<>();
-    }
-
+public final class ImmutableLeafNodeBuilder<T>
+        extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>>
+        implements LeafNode.Builder<T> {
     @Beta
     @SuppressWarnings("unchecked")
     public static <T> @NonNull LeafNode<T> createNode(final NodeIdentifier identifier, final T value) {
index acbc73609972cd8528234189020f1ac5612d7116..4ea3d9219cbaa1e4bd69102b800a7892e7d87821 100644 (file)
@@ -10,18 +10,14 @@ package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
 import static com.google.common.base.Preconditions.checkArgument;
 
 import java.util.Objects;
-import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedSimpleValueNode;
 
-public class ImmutableLeafSetEntryNodeBuilder<T>
-        extends AbstractImmutableNormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> {
-
-    public static <T> @NonNull ImmutableLeafSetEntryNodeBuilder<T> create() {
-        return new ImmutableLeafSetEntryNodeBuilder<>();
-    }
-
+// FIXME: invert encapsulation: ImmutableLeafSetEntryNode<T> should be the outer class
+public final class ImmutableLeafSetEntryNodeBuilder<T>
+        extends AbstractImmutableNormalizedNodeBuilder<NodeWithValue<T>, T, LeafSetEntryNode<T>>
+        implements LeafSetEntryNode.Builder<T> {
     @Override
     public LeafSetEntryNode<T> build() {
         return new ImmutableLeafSetEntryNode<>(getNodeIdentifier(), getValue());
index 61ba04eac555ce761f46e08e7b8ec31b4376e5ce..b6bcc29bd3ab80614131d7a69968f4adb155492e 100644 (file)
@@ -19,21 +19,20 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithV
 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.SystemLeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueNode;
 
-public class ImmutableLeafSetNodeBuilder<T> implements ListNodeBuilder<T, SystemLeafSetNode<T>> {
+public final class ImmutableLeafSetNodeBuilder<T> implements SystemLeafSetNode.Builder<T> {
     private static final int DEFAULT_CAPACITY = 4;
 
     private final Map<NodeWithValue<?>, LeafSetEntryNode<T>> value;
 
     private NodeIdentifier nodeIdentifier;
 
-    protected ImmutableLeafSetNodeBuilder() {
+    public ImmutableLeafSetNodeBuilder() {
         value = new HashMap<>(DEFAULT_CAPACITY);
     }
 
-    protected ImmutableLeafSetNodeBuilder(final int sizeHint) {
+    public ImmutableLeafSetNodeBuilder(final int sizeHint) {
         if (sizeHint >= 0) {
             value = Maps.newHashMapWithExpectedSize(sizeHint);
         } else {
@@ -41,20 +40,12 @@ public class ImmutableLeafSetNodeBuilder<T> implements ListNodeBuilder<T, System
         }
     }
 
-    protected ImmutableLeafSetNodeBuilder(final ImmutableLeafSetNode<T> node) {
+    private ImmutableLeafSetNodeBuilder(final ImmutableLeafSetNode<T> node) {
         nodeIdentifier = node.name();
         value = MapAdaptor.getDefaultInstance().takeSnapshot(node.children);
     }
 
-    public static <T> @NonNull ListNodeBuilder<T, SystemLeafSetNode<T>> create() {
-        return new ImmutableLeafSetNodeBuilder<>();
-    }
-
-    public static <T> @NonNull ListNodeBuilder<T, SystemLeafSetNode<T>> create(final int sizeHint) {
-        return new ImmutableLeafSetNodeBuilder<>(sizeHint);
-    }
-
-    public static <T> @NonNull ListNodeBuilder<T, SystemLeafSetNode<T>> create(final SystemLeafSetNode<T> node) {
+    public static <T> SystemLeafSetNode.@NonNull Builder<T> create(final SystemLeafSetNode<T> node) {
         if (node instanceof ImmutableLeafSetNode) {
             return new ImmutableLeafSetNodeBuilder<>((ImmutableLeafSetNode<T>) node);
         }
@@ -94,7 +85,7 @@ public class ImmutableLeafSetNodeBuilder<T> implements ListNodeBuilder<T, System
 
     @Override
     public ImmutableLeafSetNodeBuilder<T> withChildValue(final T childValue) {
-        return withChild(ImmutableLeafSetEntryNodeBuilder.<T>create()
+        return withChild(new ImmutableLeafSetEntryNodeBuilder<T>()
             .withNodeIdentifier(new NodeWithValue<>(nodeIdentifier.getNodeType(), childValue))
             .withValue(childValue).build());
     }
index 1219132739121de8dfd04ea4085532626971a034..a81a5a6936434d1f570642ca4bd33cbacd5bf924 100644 (file)
@@ -23,42 +23,33 @@ import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableD
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ImmutableMapEntryNodeBuilder
-        extends AbstractImmutableDataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> {
+public final class ImmutableMapEntryNodeBuilder
+        extends AbstractImmutableDataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode>
+        implements MapEntryNode.Builder {
     private static final Logger LOG = LoggerFactory.getLogger(ImmutableMapEntryNodeBuilder.class);
 
-    protected final Map<QName, NodeIdentifier> childrenQNamesToPaths;
+    private final Map<QName, NodeIdentifier> childrenQNamesToPaths;
 
-    protected ImmutableMapEntryNodeBuilder() {
+    public ImmutableMapEntryNodeBuilder() {
         childrenQNamesToPaths = new LinkedHashMap<>();
     }
 
-    protected ImmutableMapEntryNodeBuilder(final int sizeHint) {
+    public ImmutableMapEntryNodeBuilder(final int sizeHint) {
         super(sizeHint);
         childrenQNamesToPaths = new LinkedHashMap<>(sizeHint);
     }
 
-    protected ImmutableMapEntryNodeBuilder(final ImmutableMapEntryNode node) {
+    private ImmutableMapEntryNodeBuilder(final ImmutableMapEntryNode node) {
         super(node);
         childrenQNamesToPaths = new LinkedHashMap<>();
         fillQNames(node.body(), childrenQNamesToPaths);
     }
 
-    public static @NonNull DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> create() {
-        return new ImmutableMapEntryNodeBuilder();
-    }
-
-    public static @NonNull DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> create(
-            final int sizeHint) {
-        return new ImmutableMapEntryNodeBuilder(sizeHint);
-    }
-
-    public static @NonNull DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> create(
-            final MapEntryNode node) {
-        if (!(node instanceof ImmutableMapEntryNode immutableNode)) {
-            throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
+    public static MapEntryNode.@NonNull Builder create(final MapEntryNode node) {
+        if (node instanceof ImmutableMapEntryNode immutableNode) {
+            return new ImmutableMapEntryNodeBuilder(immutableNode);
         }
-        return new ImmutableMapEntryNodeBuilder(immutableNode);
+        throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
     }
 
     private static void fillQNames(final Iterable<DataContainerChild> iterable, final Map<QName, NodeIdentifier> out) {
index 8d0544bb42f0e91b4593a88fc023242adac681b6..6f891df01caff25894e4a501a683dfd79c011141 100644 (file)
@@ -22,21 +22,20 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
 import org.opendaylight.yangtools.yang.data.spi.node.AbstractNormalizedNode;
 
-public class ImmutableMapNodeBuilder implements CollectionNodeBuilder<MapEntryNode, SystemMapNode> {
+public final class ImmutableMapNodeBuilder implements SystemMapNode.Builder {
     private static final int DEFAULT_CAPACITY = 4;
 
     private final Map<NodeIdentifierWithPredicates, MapEntryNode> value;
 
     private @Nullable NodeIdentifier nodeIdentifier = null;
 
-    protected ImmutableMapNodeBuilder() {
+    public ImmutableMapNodeBuilder() {
         value = new HashMap<>(DEFAULT_CAPACITY);
     }
 
-    protected ImmutableMapNodeBuilder(final int sizeHint) {
+    public ImmutableMapNodeBuilder(final int sizeHint) {
         if (sizeHint >= 0) {
             value = Maps.newHashMapWithExpectedSize(sizeHint);
         } else {
@@ -44,20 +43,12 @@ public class ImmutableMapNodeBuilder implements CollectionNodeBuilder<MapEntryNo
         }
     }
 
-    protected ImmutableMapNodeBuilder(final SystemMapNode node) {
+    private ImmutableMapNodeBuilder(final SystemMapNode node) {
         nodeIdentifier = node.name();
         value = MapAdaptor.getDefaultInstance().takeSnapshot(accessChildren(node));
     }
 
-    public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> create() {
-        return new ImmutableMapNodeBuilder();
-    }
-
-    public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> create(final int sizeHint) {
-        return new ImmutableMapNodeBuilder(sizeHint);
-    }
-
-    public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> create(final SystemMapNode node) {
+    public static SystemMapNode.@NonNull Builder create(final SystemMapNode node) {
         return new ImmutableMapNodeBuilder(node);
     }
 
index 1a7b311ec8947bfa73ab5d2a5674275b7052ec4f..beb5fbf4aac16b3640682dc5b6b2603482c2648e 100644 (file)
@@ -14,36 +14,27 @@ import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerNode;
 
-public class ImmutableUnkeyedListEntryNodeBuilder
-        extends AbstractImmutableDataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> {
-
-    protected ImmutableUnkeyedListEntryNodeBuilder() {
+public final class ImmutableUnkeyedListEntryNodeBuilder
+        extends AbstractImmutableDataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode>
+        implements UnkeyedListEntryNode.Builder {
+    public ImmutableUnkeyedListEntryNodeBuilder() {
 
     }
 
-    protected ImmutableUnkeyedListEntryNodeBuilder(final int sizeHint) {
+    public ImmutableUnkeyedListEntryNodeBuilder(final int sizeHint) {
         super(sizeHint);
     }
 
-    protected ImmutableUnkeyedListEntryNodeBuilder(final ImmutableUnkeyedListEntryNode node) {
+    private ImmutableUnkeyedListEntryNodeBuilder(final ImmutableUnkeyedListEntryNode node) {
         super(node);
     }
 
-    public static @NonNull DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> create() {
-        return new ImmutableUnkeyedListEntryNodeBuilder();
-    }
-
-    public static @NonNull DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> create(
-            final int sizeHint) {
-        return new ImmutableUnkeyedListEntryNodeBuilder(sizeHint);
-    }
-
     public static @NonNull DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> create(
             final UnkeyedListEntryNode node) {
-        if (!(node instanceof ImmutableUnkeyedListEntryNode immutableNode)) {
-            throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
+        if (node instanceof ImmutableUnkeyedListEntryNode immutableNode) {
+            return new ImmutableUnkeyedListEntryNodeBuilder(immutableNode);
         }
-        return new ImmutableUnkeyedListEntryNodeBuilder(immutableNode);
+        throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
     }
 
     @Override
index eb912cb7f6b4e0d1ad780f7bd8cbe68db889a508..e8569d111fb42152ee2651fe4fe688142cf131ce 100644 (file)
@@ -22,16 +22,21 @@ import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeCon
 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueNode;
 import org.opendaylight.yangtools.yang.data.spi.node.AbstractNormalizedNode;
 
-public class ImmutableUnkeyedListNodeBuilder implements CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> {
+public final class ImmutableUnkeyedListNodeBuilder implements UnkeyedListNode.Builder {
     private List<UnkeyedListEntryNode> value;
     private NodeIdentifier nodeIdentifier;
     private boolean dirty;
 
-    protected ImmutableUnkeyedListNodeBuilder() {
+    public ImmutableUnkeyedListNodeBuilder() {
         value = new LinkedList<>();
         dirty = false;
     }
 
+    public ImmutableUnkeyedListNodeBuilder(final int sizeHint) {
+        this();
+    }
+
+
     protected ImmutableUnkeyedListNodeBuilder(final ImmutableUnkeyedListNode node) {
         nodeIdentifier = node.name();
         // FIXME: clean this up, notably reuse unmodified lists
@@ -40,16 +45,7 @@ public class ImmutableUnkeyedListNodeBuilder implements CollectionNodeBuilder<Un
         dirty = true;
     }
 
-    public static CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> create() {
-        return new ImmutableUnkeyedListNodeBuilder();
-    }
-
-    public static CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> create(final int sizeHint) {
-        return new ImmutableUnkeyedListNodeBuilder();
-    }
-
-    public static CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> create(
-            final UnkeyedListNode node) {
+    public static UnkeyedListNode.@NonNull Builder create(final UnkeyedListNode node) {
         if (!(node instanceof ImmutableUnkeyedListNode immutableNode)) {
             throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
         }
index 24dda7bf9c2448b0d88f476976d979f8ebb0a75f..0d58cda8668e0857294abd8036fbd6ac10f84b23 100644 (file)
@@ -19,15 +19,15 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithV
 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.UserLeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.spi.node.AbstractNormalizedNode;
 
-public class ImmutableUserLeafSetNodeBuilder<T> implements ListNodeBuilder<T, UserLeafSetNode<T>> {
-    private Map<NodeWithValue, LeafSetEntryNode<T>> value;
+public final class ImmutableUserLeafSetNodeBuilder<T> implements UserLeafSetNode.Builder<T> {
+    private Map<NodeWithValue<T>, LeafSetEntryNode<T>> value;
     private NodeIdentifier nodeIdentifier;
     private boolean dirty;
 
-    ImmutableUserLeafSetNodeBuilder() {
+    public ImmutableUserLeafSetNodeBuilder() {
         value = new LinkedHashMap<>();
         dirty = false;
     }
@@ -38,17 +38,11 @@ public class ImmutableUserLeafSetNodeBuilder<T> implements ListNodeBuilder<T, Us
         dirty = true;
     }
 
-    public static <T> @NonNull ListNodeBuilder<T, UserLeafSetNode<T>> create() {
-        return new ImmutableUserLeafSetNodeBuilder<>();
-    }
-
-    public static <T> @NonNull ListNodeBuilder<T, UserLeafSetNode<T>> create(
-            final UserLeafSetNode<T> node) {
-        if (!(node instanceof ImmutableUserLeafSetNode<?>)) {
-            throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
+    public static <T> UserLeafSetNode.@NonNull Builder<T> create(final UserLeafSetNode<T> node) {
+        if (node instanceof ImmutableUserLeafSetNode<?>) {
+            return new ImmutableUserLeafSetNodeBuilder<>((ImmutableUserLeafSetNode<T>) node);
         }
-
-        return new ImmutableUserLeafSetNodeBuilder<>((ImmutableUserLeafSetNode<T>) node);
+        throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
     }
 
     private void checkDirty() {
@@ -95,7 +89,7 @@ public class ImmutableUserLeafSetNodeBuilder<T> implements ListNodeBuilder<T, Us
 
     @Override
     public ImmutableUserLeafSetNodeBuilder<T> withChildValue(final T childValue) {
-        return withChild(ImmutableLeafSetEntryNodeBuilder.<T>create()
+        return withChild(Builders.<T>leafSetEntryBuilder()
             .withNodeIdentifier(new NodeWithValue<>(nodeIdentifier.getNodeType(), childValue))
             .withValue(childValue).build());
     }
@@ -103,10 +97,10 @@ public class ImmutableUserLeafSetNodeBuilder<T> implements ListNodeBuilder<T, Us
     protected static final class ImmutableUserLeafSetNode<T>
             extends AbstractNormalizedNode<NodeIdentifier, UserLeafSetNode<?>>
             implements UserLeafSetNode<T> {
-        private final Map<NodeWithValue, LeafSetEntryNode<T>> children;
+        private final Map<NodeWithValue<T>, LeafSetEntryNode<T>> children;
 
         ImmutableUserLeafSetNode(final NodeIdentifier nodeIdentifier,
-                final Map<NodeWithValue, LeafSetEntryNode<T>> children) {
+                final Map<NodeWithValue<T>, LeafSetEntryNode<T>> children) {
             super(nodeIdentifier);
             this.children = children;
         }
@@ -150,7 +144,7 @@ public class ImmutableUserLeafSetNodeBuilder<T> implements ListNodeBuilder<T, Us
             return Iterables.elementsEqual(children.values(), other.body());
         }
 
-        private Map<NodeWithValue, LeafSetEntryNode<T>> getChildren() {
+        private Map<NodeWithValue<T>, LeafSetEntryNode<T>> getChildren() {
             return Collections.unmodifiableMap(children);
         }
     }
index 77e069e6773f2a03ba356b1c716b237cf0fa4f5a..d0497826ba6d045ef68668dbad04ec1e58c8a4d1 100644 (file)
@@ -23,19 +23,19 @@ import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBui
 import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder;
 import org.opendaylight.yangtools.yang.data.spi.node.AbstractNormalizedNode;
 
-public class ImmutableUserMapNodeBuilder implements CollectionNodeBuilder<MapEntryNode, UserMapNode> {
+public final class ImmutableUserMapNodeBuilder implements UserMapNode.Builder {
     private static final int DEFAULT_CAPACITY = 4;
 
     private Map<NodeIdentifierWithPredicates, MapEntryNode> value;
     private NodeIdentifier nodeIdentifier;
     private boolean dirty;
 
-    ImmutableUserMapNodeBuilder() {
+    public ImmutableUserMapNodeBuilder() {
         value = new LinkedHashMap<>(DEFAULT_CAPACITY);
         dirty = false;
     }
 
-    private ImmutableUserMapNodeBuilder(final int sizeHint) {
+    public ImmutableUserMapNodeBuilder(final int sizeHint) {
         if (sizeHint >= 0) {
             value = new LinkedHashMap<>(sizeHint + sizeHint / 3);
         } else {
@@ -50,19 +50,11 @@ public class ImmutableUserMapNodeBuilder implements CollectionNodeBuilder<MapEnt
         dirty = true;
     }
 
-    public static @NonNull CollectionNodeBuilder<MapEntryNode, UserMapNode> create() {
-        return new ImmutableUserMapNodeBuilder();
-    }
-
-    public static @NonNull CollectionNodeBuilder<MapEntryNode, UserMapNode> create(final int sizeHint) {
-        return new ImmutableUserMapNodeBuilder(sizeHint);
-    }
-
-    public static @NonNull CollectionNodeBuilder<MapEntryNode, UserMapNode> create(final UserMapNode node) {
-        if (!(node instanceof ImmutableUserMapNode immutableNode)) {
-            throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
+    public static UserMapNode.@NonNull Builder create(final UserMapNode node) {
+        if (node instanceof ImmutableUserMapNode immutableNode) {
+            return new ImmutableUserMapNodeBuilder(immutableNode);
         }
-        return new ImmutableUserMapNodeBuilder(immutableNode);
+        throw new UnsupportedOperationException("Cannot initialize from class " + node.getClass());
     }
 
     private void checkDirty() {
index b9e60a3e23e3d521aed818883611dd20c5ed4fb6..6384d87d80a9b0f5ca8e258c7875020541aa3fc0 100644 (file)
@@ -23,14 +23,9 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeBuilder;
 
 class BuilderTest {
@@ -51,24 +46,24 @@ class BuilderTest {
     private static final int SIZE = 3;
     private static final NodeWithValue<String> BAR_PATH = new NodeWithValue<>(LEAF_LIST_MAIN, "bar");
     private static final LeafSetEntryNode<String> LEAF_SET_ENTRY_NODE =
-            ImmutableLeafSetEntryNodeBuilder.<String>create().withNodeIdentifier(BAR_PATH).withValue("bar").build();
+            new ImmutableLeafSetEntryNodeBuilder<String>().withNodeIdentifier(BAR_PATH).withValue("bar").build();
 
     @Test
     void immutableOrderedMapBuilderTest() {
         final var mapEntryPath = NodeIdentifierWithPredicates.of(LIST_MAIN, LIST_MAIN_CHILD_QNAME_1, 1);
-        final var orderedMapNodeCreateNull = ImmutableUserMapNodeBuilder.create()
+        final var orderedMapNodeCreateNull = Builders.orderedMapBuilder()
                 .withNodeIdentifier(NODE_IDENTIFIER_LIST)
                 .withChild(LIST_MAIN_CHILD_1)
                 .addChild(LIST_MAIN_CHILD_2)
                 .withValue(List.of(LIST_MAIN_CHILD_3))
                 .build();
-        final var orderedMapNodeCreateSize = ImmutableUserMapNodeBuilder.create(SIZE)
+        final var orderedMapNodeCreateSize = Builders.orderedMapBuilder(SIZE)
                 .withNodeIdentifier(NODE_IDENTIFIER_LIST)
                 .build();
         final var orderedMapNodeCreateNode = ImmutableUserMapNodeBuilder.create(orderedMapNodeCreateNull)
                 .removeChild(mapEntryPath)
                 .build();
-        final var orderedMapNodeSchemaAware = ImmutableUserMapNodeBuilder.create()
+        final var orderedMapNodeSchemaAware = Builders.orderedMapBuilder()
                 .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
                 .withChild(LIST_MAIN_CHILD_1)
                 .build();
@@ -86,13 +81,13 @@ class BuilderTest {
 
     @Test
     void immutableUserLeafSetNodeBuilderTest() {
-        final var orderedLeafSet = ImmutableUserLeafSetNodeBuilder.<String>create()
+        final var orderedLeafSet = Builders.<String>orderedLeafSetBuilder()
                 .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
                 .withChild(LEAF_SET_ENTRY_NODE)
                 .withChildValue("baz")
                 .removeChild(BAR_PATH)
                 .build();
-        final var orderedMapNodeSchemaAware = ImmutableUserLeafSetNodeBuilder.create()
+        final var orderedMapNodeSchemaAware = Builders.orderedLeafSetBuilder()
             .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
             .withChildValue("baz")
             .build();
@@ -107,7 +102,7 @@ class BuilderTest {
 
     @Test
     void immutableMapNodeBuilderTest() {
-        final var mapNode = ImmutableMapNodeBuilder.create(1)
+        final var mapNode = Builders.mapBuilder(1)
             .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
             .withValue(List.of(LIST_MAIN_CHILD_3))
             .build();
@@ -116,30 +111,28 @@ class BuilderTest {
 
     @Test
     void immutableUnkeyedListEntryNodeBuilderTest() {
-        final var unkeyedListEntryNode = ImmutableUnkeyedListEntryNodeBuilder.create()
+        final var unkeyedListEntryNode = Builders.unkeyedListEntryBuilder()
                 .withNodeIdentifier(NODE_IDENTIFIER_LIST)
                 .build();
-        final var unkeyedListEntryNodeSize = ImmutableUnkeyedListEntryNodeBuilder.create(1)
+        final var unkeyedListEntryNodeSize = Builders.unkeyedListEntryBuilder(1)
                 .withNodeIdentifier(NODE_IDENTIFIER_LIST)
                 .build();
-        final var unkeyedListEntryNodeNode = ImmutableUnkeyedListEntryNodeBuilder
-                .create(unkeyedListEntryNode).build();
+        final var unkeyedListEntryNodeNode = ImmutableUnkeyedListEntryNodeBuilder.create(unkeyedListEntryNode).build();
         assertEquals(unkeyedListEntryNode.name(), unkeyedListEntryNodeSize.name());
         assertEquals(unkeyedListEntryNodeSize.name(), unkeyedListEntryNodeNode.name());
     }
 
     @Test
     void immutableUnkeyedListNodeBuilderTest() {
-        final var unkeyedListEntryNode = ImmutableUnkeyedListEntryNodeBuilder.create()
+        final var unkeyedListEntryNode = Builders.unkeyedListEntryBuilder()
                 .withNodeIdentifier(NODE_IDENTIFIER_LEAF)
                 .build();
-        final var immutableUnkeyedListNodeBuilder = (ImmutableUnkeyedListNodeBuilder)
-                ImmutableUnkeyedListNodeBuilder.create();
+        final var immutableUnkeyedListNodeBuilder = Builders.unkeyedListBuilder();
         final var unkeyedListNode = immutableUnkeyedListNodeBuilder
                 .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
                 .addChild(unkeyedListEntryNode)
                 .build();
-        final var unkeyedListNodeSize = ImmutableUnkeyedListNodeBuilder.create(1)
+        final var unkeyedListNodeSize = Builders.unkeyedListBuilder(1)
                 .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
                 .build();
         final var unkeyedListNodeCreated = ImmutableUnkeyedListNodeBuilder.create(unkeyedListNode)
@@ -155,42 +148,37 @@ class BuilderTest {
 
     @Test
     void immutableChoiceNodeBuilderTest() {
-        final var choiceNode = ImmutableChoiceNodeBuilder.create(1).withNodeIdentifier(NODE_IDENTIFIER_LIST)
-                .build();
+        final var choiceNode = Builders.choiceBuilder(1).withNodeIdentifier(NODE_IDENTIFIER_LIST).build();
         final var choiceNodeCreated = ImmutableChoiceNodeBuilder.create(choiceNode).build();
-        assertEquals(choiceNodeCreated.name(), choiceNode.name());
+        assertEquals(choiceNode, choiceNodeCreated);
     }
 
     @Test
     void immutableContainerNodeBuilderExceptionTest() {
-        final var immutableContainerNode = ImmutableContainerNodeBuilder.create(1)
-                .withNodeIdentifier(NODE_IDENTIFIER_LIST)
-                .build();
-        assertNotNull(immutableContainerNode);
+        final var containerNode = Builders.containerBuilder(1).withNodeIdentifier(NODE_IDENTIFIER_LIST).build();
+        assertNotNull(containerNode);
     }
 
     @Test
     void immutableLeafSetNodeBuilderExceptionTest() {
-        final var leafSetNode = ImmutableLeafSetNodeBuilder.create(1)
-                .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
-                .build();
+        final var leafSetNode = Builders.leafSetBuilder(1).withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST).build();
         assertNotNull(leafSetNode);
     }
 
     @Test
     void immutableMapEntryNodeBuilderExceptionTest() {
-        final var builder = ImmutableMapEntryNodeBuilder.create(1);
+        final var builder = Builders.mapEntryBuilder(1);
         assertThrows(NullPointerException.class, builder::build);
     }
 
     @Test
     void immutableUnkeyedListNodeBuilderExceptionTest() {
-        final var builder = ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LEAF);
+        final var builder = Builders.unkeyedListBuilder().withNodeIdentifier(NODE_IDENTIFIER_LEAF);
         assertThrows(UnsupportedOperationException.class, () -> builder.removeChild(NODE_IDENTIFIER_LIST));
     }
 
     private static UserMapNode getImmutableUserMapNode() {
-        return ImmutableUserMapNodeBuilder.create()
+        return Builders.orderedMapBuilder()
             .withNodeIdentifier(NODE_IDENTIFIER_LIST)
             .withChild(LIST_MAIN_CHILD_1)
             .build();
index 9a89ef3b9297b8ccd140f07e59070e9f73adb448..5b2134f5c25733871ea5552526f2ec90fa81b462 100644 (file)
@@ -44,7 +44,7 @@ class InstanceIdToNodesTest {
             QName.create(NS, REVISION, "outer-list"), ID, 1);
 
     private final NodeIdentifier leafList = new NodeIdentifier(QName.create(NS, REVISION, "ordered-leaf-list"));
-    private final NodeWithValue<?> leafListWithValue = new NodeWithValue<>(leafList.getNodeType(), "abcd");
+    private final NodeWithValue<String> leafListWithValue = new NodeWithValue<>(leafList.getNodeType(), "abcd");
 
     @BeforeAll
     static void setUp() {
@@ -78,9 +78,9 @@ class InstanceIdToNodesTest {
     void testLeafList() {
         assertEquals(Builders.containerBuilder()
             .withNodeIdentifier(rootContainer)
-            .withChild(Builders.orderedLeafSetBuilder()
+            .withChild(Builders.<String>orderedLeafSetBuilder()
                 .withNodeIdentifier(leafList)
-                .withChild(Builders.leafSetEntryBuilder()
+                .withChild(Builders.<String>leafSetEntryBuilder()
                     .withNodeIdentifier(leafListWithValue)
                     .withValue(leafListWithValue.getValue())
                     .build())
index 8bd551bc8b89c15028448ed78db9d0d0c26db65d..bb7e38f790cf2457b84b1e5dc46c8fd5710ca447 100644 (file)
@@ -20,7 +20,6 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 
 /*
 * Schema structure of document is:
@@ -87,7 +86,7 @@ class NormalizedNodeUtilsTest {
      * @return A test document
      */
     private static NormalizedNode createDocumentOne() {
-        return ImmutableContainerNodeBuilder.create()
+        return Builders.containerBuilder()
             .withNodeIdentifier(new NodeIdentifier(ROOT_QNAME))
             .withChild(mapNodeBuilder(LIST_A_QNAME)
                 .withChild(mapEntry(LIST_A_QNAME, LEAF_A_QNAME, FOO))
index 32706aaf389041ee0a92684fa76e606bb12fde39..5c65500a21a6033a4d461a31d57ff3f744a0208f 100644 (file)
@@ -31,7 +31,7 @@ import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 final class ChoiceModificationStrategy extends Visible<ChoiceSchemaNode> {
     private static final NormalizedNodeContainerSupport<NodeIdentifier, ChoiceNode> SUPPORT =
             new NormalizedNodeContainerSupport<>(ChoiceNode.class, ImmutableChoiceNodeBuilder::create,
-                    ImmutableChoiceNodeBuilder::create);
+                    ImmutableChoiceNodeBuilder::new);
 
     private final ImmutableMap<PathArgument, ModificationApplyOperation> childNodes;
     // FIXME: enforce leaves not coming from two case statements at the same time
index b521c29f2d6a9723ff1bd36f4da16ddd41d12743..f0955272bf746ee13bba96680a42f4394a377d91 100644 (file)
@@ -96,7 +96,7 @@ sealed class ContainerModificationStrategy extends DataNodeContainerModification
 
     private static final NormalizedNodeContainerSupport<NodeIdentifier, ContainerNode> SUPPORT =
             new NormalizedNodeContainerSupport<>(ContainerNode.class, ImmutableContainerNodeBuilder::create,
-                    ImmutableContainerNodeBuilder::create);
+                    ImmutableContainerNodeBuilder::new);
 
     ContainerModificationStrategy(final ContainerLike schemaNode, final DataTreeConfiguration treeConfig) {
         super(SUPPORT, schemaNode, treeConfig);
index 218f1b43c0f62c884d855fa2415f9afa8d3594b5..e25e2b89db006577161dfb79c0b6531362e61391 100644 (file)
@@ -23,13 +23,13 @@ final class LeafSetModificationStrategy extends Invisible<LeafListSchemaNode> {
     @SuppressWarnings({ "unchecked", "rawtypes" })
     private static final NormalizedNodeContainerSupport<NodeIdentifier, UserLeafSetNode<?>> ORDERED_SUPPORT =
             new NormalizedNodeContainerSupport(UserLeafSetNode.class, ChildTrackingPolicy.ORDERED,
-                foo -> ImmutableUserLeafSetNodeBuilder.create((UserLeafSetNode<?>)foo),
-                ImmutableUserLeafSetNodeBuilder::create);
+                foo -> ImmutableUserLeafSetNodeBuilder.create((UserLeafSetNode<?>) foo),
+                ImmutableUserLeafSetNodeBuilder::new);
     @SuppressWarnings({ "unchecked", "rawtypes" })
     private static final NormalizedNodeContainerSupport<NodeIdentifier, SystemLeafSetNode<?>> UNORDERED_SUPPORT =
             new NormalizedNodeContainerSupport(SystemLeafSetNode.class,
-                foo -> ImmutableLeafSetNodeBuilder.create((SystemLeafSetNode<?>)foo),
-                ImmutableLeafSetNodeBuilder::create);
+                foo -> ImmutableLeafSetNodeBuilder.create((SystemLeafSetNode<?>) foo),
+                ImmutableLeafSetNodeBuilder::new);
 
     LeafSetModificationStrategy(final LeafListSchemaNode schema, final DataTreeConfiguration treeConfig) {
         super(schema.isUserOrdered() ? ORDERED_SUPPORT : UNORDERED_SUPPORT, treeConfig,
index f6d1e03862b05e003500ddbb62d9b598e86e4bd6..ac2cc3c4bf90db98ead309163c53e74ff550f30f 100644 (file)
@@ -27,7 +27,7 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 final class ListModificationStrategy extends SchemaAwareApplyOperation<ListSchemaNode> {
     private static final NormalizedNodeContainerSupport<NodeIdentifier, UnkeyedListEntryNode> ITEM_SUPPORT =
             new NormalizedNodeContainerSupport<>(UnkeyedListEntryNode.class,
-                    ImmutableUnkeyedListEntryNodeBuilder::create, ImmutableUnkeyedListEntryNodeBuilder::create);
+                    ImmutableUnkeyedListEntryNodeBuilder::create, ImmutableUnkeyedListEntryNodeBuilder::new);
 
     private final DataNodeContainerModificationStrategy<ListSchemaNode> entryStrategy;
     private final UnkeyedListNode emptyNode;
index 4e0fa476afc53876243ec092ab2a03bfda401a95..a809b0da2c06332f480a206d00aa27577470cd6d 100644 (file)
@@ -62,7 +62,7 @@ sealed class MapEntryModificationStrategy extends DataNodeContainerModificationS
 
     private static final NormalizedNodeContainerSupport<NodeIdentifierWithPredicates, MapEntryNode> SUPPORT =
             new NormalizedNodeContainerSupport<>(MapEntryNode.class, ImmutableMapEntryNodeBuilder::create,
-                    ImmutableMapEntryNodeBuilder::create);
+                    ImmutableMapEntryNodeBuilder::new);
 
     MapEntryModificationStrategy(final ListSchemaNode schema, final DataTreeConfiguration treeConfig) {
         super(SUPPORT, schema, treeConfig);
index 71e009f9666b6b512895738c7796c10f5e5ab420..32383d0132253da5af90a6109662317b24aa2611 100644 (file)
@@ -28,10 +28,10 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 final class MapModificationStrategy extends Invisible<ListSchemaNode> {
     private static final NormalizedNodeContainerSupport<NodeIdentifier, UserMapNode> ORDERED_SUPPORT =
             new NormalizedNodeContainerSupport<>(UserMapNode.class, ChildTrackingPolicy.ORDERED,
-                    ImmutableUserMapNodeBuilder::create, ImmutableUserMapNodeBuilder::create);
+                    ImmutableUserMapNodeBuilder::create, ImmutableUserMapNodeBuilder::new);
     private static final NormalizedNodeContainerSupport<NodeIdentifier, SystemMapNode> UNORDERED_SUPPORT =
             new NormalizedNodeContainerSupport<>(SystemMapNode.class, ImmutableMapNodeBuilder::create,
-                    ImmutableMapNodeBuilder::create);
+                    ImmutableMapNodeBuilder::new);
 
     private final @NonNull MapNode emptyNode;
 
index 8b191d706da5a5fc2e9d20014deffd14791d9bf3..320624ab2171e7642439cb31e91a4505263c1266 100644 (file)
@@ -308,10 +308,10 @@ class Bug4454Test {
         final var barPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "bar");
         final var gooPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "goo");
 
-        final var barLeafSetEntry = Builders.leafSetEntryBuilder()
+        final var barLeafSetEntry = Builders.<String>leafSetEntryBuilder()
                 .withNodeIdentifier(barPath)
                 .withValue("bar").build();
-        final var gooLeafSetEntry = Builders.leafSetEntryBuilder()
+        final var gooLeafSetEntry = Builders.<String>leafSetEntryBuilder()
                 .withNodeIdentifier(gooPath)
                 .withValue("goo").build();
 
index f6a1c9b47153c8b31214647cf3260cac038eee50..99b850951a5e7f8e9c613cc6cb10d14c3104e38e 100644 (file)
@@ -229,11 +229,11 @@ class ListConstraintsValidation {
             .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME))
             .withChildValue("foo")
             .build());
-        modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), Builders.leafSetEntryBuilder()
+        modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), Builders.<String>leafSetEntryBuilder()
             .withNodeIdentifier(barPath)
             .withValue("bar")
             .build());
-        modificationTree.merge(MIN_MAX_LEAF_LIST_PATH.node(gooPath), Builders.leafSetEntryBuilder()
+        modificationTree.merge(MIN_MAX_LEAF_LIST_PATH.node(gooPath), Builders.<String>leafSetEntryBuilder()
             .withNodeIdentifier(gooPath)
             .withValue("goo")
             .build());
@@ -266,15 +266,15 @@ class ListConstraintsValidation {
             .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME))
             .withChildValue("foo")
             .build());
-        modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), Builders.leafSetEntryBuilder()
+        modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), Builders.<String>leafSetEntryBuilder()
             .withNodeIdentifier(barPath)
             .withValue("bar")
             .build());
-        modificationTree.merge(MIN_MAX_LEAF_LIST_PATH.node(gooPath), Builders.leafSetEntryBuilder()
+        modificationTree.merge(MIN_MAX_LEAF_LIST_PATH.node(gooPath), Builders.<String>leafSetEntryBuilder()
             .withNodeIdentifier(gooPath)
             .withValue("goo")
             .build());
-        modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(fuuPath), Builders.leafSetEntryBuilder()
+        modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(fuuPath), Builders.<String>leafSetEntryBuilder()
             .withNodeIdentifier(fuuPath)
             .withValue("fuu")
             .build());