Cleanup yang-data-impl nullness annotations
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / InMemoryDataTreeFactory.java
index 381184e4dd6a87236378992f5859b8c95b10acc8..b36776d88c479ed86695185e768c801830cce934 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
 import com.google.common.base.Preconditions;
+import org.kohsuke.MetaInfServices;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@@ -17,12 +18,9 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration.Builder;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeFactory;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
@@ -38,42 +36,12 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 /**
  * A factory for creating in-memory data trees.
  */
+@MetaInfServices
 public final class InMemoryDataTreeFactory implements DataTreeFactory {
-    private static final InMemoryDataTreeFactory INSTANCE = new InMemoryDataTreeFactory();
     private static final NormalizedNode<?, ?> ROOT_CONTAINER = ImmutableNodes.containerNode(SchemaContext.NAME);
 
-    private InMemoryDataTreeFactory() {
-        // Never instantiated externally
-    }
-
-    @Deprecated
-    @Override
-    public TipProducingDataTree create(final TreeType treeType) {
-        return create(DataTreeConfiguration.getDefault(treeType));
-    }
-
-    @Deprecated
-    @Override
-    public TipProducingDataTree create(final TreeType treeType, final YangInstanceIdentifier rootPath) {
-        if (rootPath.isEmpty()) {
-            return create(treeType);
-        }
-
-        final DataTreeConfiguration defConfig = DataTreeConfiguration.getDefault(treeType);
-        final DataTreeConfiguration config;
-        if (!rootPath.isEmpty()) {
-            config = new Builder(treeType).setMandatoryNodesValidation(defConfig.isMandatoryNodesValidationEnabled())
-                    .setRootPath(rootPath).setUniqueIndexes(defConfig.isUniqueIndexEnabled()).build();
-        } else {
-            config = defConfig;
-        }
-
-        return new InMemoryDataTree(TreeNodeFactory.createTreeNode(createRoot(rootPath), Version.initial()), config,
-            null);
-    }
-
     @Override
-    public TipProducingDataTree create(final DataTreeConfiguration treeConfig) {
+    public DataTree create(final DataTreeConfiguration treeConfig) {
         return new InMemoryDataTree(TreeNodeFactory.createTreeNode(createRoot(treeConfig.getRootPath()),
             Version.initial()), treeConfig, null);
     }
@@ -107,6 +75,18 @@ public final class InMemoryDataTreeFactory implements DataTreeFactory {
             initialSchemaContext, rootSchemaNode, maskMandatory);
     }
 
+    private static DataSchemaNode getRootSchemaNode(final SchemaContext schemaContext,
+            final YangInstanceIdentifier rootPath) {
+        final DataSchemaContextTree contextTree = DataSchemaContextTree.from(schemaContext);
+        final DataSchemaContextNode<?> rootContextNode = contextTree.getChild(rootPath);
+        Preconditions.checkArgument(rootContextNode != null, "Failed to find root %s in schema context", rootPath);
+
+        final DataSchemaNode rootSchemaNode = rootContextNode.getDataSchemaNode();
+        Preconditions.checkArgument(rootSchemaNode instanceof DataNodeContainer,
+            "Root %s resolves to non-container type %s", rootPath, rootSchemaNode);
+        return rootSchemaNode;
+    }
+
     private static NormalizedNode<?, ?> createRoot(final DataNodeContainer schemaNode,
             final YangInstanceIdentifier path) {
         if (path.isEmpty()) {
@@ -132,18 +112,6 @@ public final class InMemoryDataTreeFactory implements DataTreeFactory {
         }
     }
 
-    private static DataSchemaNode getRootSchemaNode(final SchemaContext schemaContext,
-            final YangInstanceIdentifier rootPath) {
-        final DataSchemaContextTree contextTree = DataSchemaContextTree.from(schemaContext);
-        final DataSchemaContextNode<?> rootContextNode = contextTree.getChild(rootPath);
-        Preconditions.checkArgument(rootContextNode != null, "Failed to find root %s in schema context", rootPath);
-
-        final DataSchemaNode rootSchemaNode = rootContextNode.getDataSchemaNode();
-        Preconditions.checkArgument(rootSchemaNode instanceof DataNodeContainer,
-            "Root %s resolves to non-container type %s", rootPath, rootSchemaNode);
-        return rootSchemaNode;
-    }
-
     private static NormalizedNode<?, ?> createRoot(final YangInstanceIdentifier path) {
         if (path.isEmpty()) {
             return ROOT_CONTAINER;
@@ -160,13 +128,4 @@ public final class InMemoryDataTreeFactory implements DataTreeFactory {
         // FIXME: implement augmentations and leaf-lists
         throw new IllegalArgumentException("Unsupported root node " + arg);
     }
-
-    /**
-     * Get an instance of this factory. This method cannot fail.
-     *
-     * @return Data tree factory instance.
-     */
-    public static InMemoryDataTreeFactory getInstance() {
-        return INSTANCE;
-    }
 }