Use varhandles in InMemoryDataTree
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / SchemaUtils.java
index 986bcd0129f59d398d0d50dcd4bc433528b778c9..9747829b393cfc7c777546a486d0714e2137fb0c 100644 (file)
@@ -15,7 +15,6 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -29,7 +28,6 @@ import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
 import org.opendaylight.yangtools.yang.model.api.ActionNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
@@ -67,10 +65,9 @@ public final class SchemaUtils {
                     }
                 } else if (dsn instanceof ChoiceSchemaNode) {
                     for (final CaseSchemaNode choiceCase : ((ChoiceSchemaNode) dsn).getCases().values()) {
-
-                        final DataSchemaNode dataChildByName = choiceCase.getDataChildByName(qname);
-                        if (dataChildByName != null) {
-                            return Optional.of(dataChildByName);
+                        final Optional<DataSchemaNode> dataChildByName = choiceCase.findDataChildByName(qname);
+                        if (dataChildByName.isPresent()) {
+                            return dataChildByName;
                         }
                         final Optional<DataSchemaNode> foundDsn = findFirstSchema(qname, choiceCase.getChildNodes());
                         if (foundDsn.isPresent()) {
@@ -94,8 +91,9 @@ public final class SchemaUtils {
     public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname) {
         // Try to find child schema node directly, but use a fallback that compares QNames without revisions
         // and auto-expands choices
-        final DataSchemaNode dataChildByName = schema.getDataChildByName(qname);
-        return dataChildByName == null ? findSchemaForChild(schema, qname, schema.getChildNodes()) : dataChildByName;
+        final Optional<DataSchemaNode> dataChildByName = schema.findDataChildByName(qname);
+        return dataChildByName.isPresent() ? dataChildByName.get()
+                : findSchemaForChild(schema, qname, schema.getChildNodes());
     }
 
     public static @Nullable DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname,
@@ -204,7 +202,7 @@ public final class SchemaUtils {
         }
 
         for (final AugmentationSchemaNode augmentation : ((AugmentationTarget) schema).getAvailableAugmentations()) {
-            if (augmentation.getDataChildByName(childSchema.getQName()) != null) {
+            if (augmentation.findDataChildByName(childSchema.getQName()).isPresent()) {
                 return true;
             }
         }
@@ -313,7 +311,7 @@ public final class SchemaUtils {
     public static Set<DataSchemaNode> getRealSchemasForAugment(final AugmentationTarget targetSchema,
             final AugmentationSchemaNode augmentSchema) {
         if (!targetSchema.getAvailableAugmentations().contains(augmentSchema)) {
-            return Collections.emptySet();
+            return ImmutableSet.of();
         }
         if (targetSchema instanceof DataNodeContainer) {
             return getRealSchemasForAugment((DataNodeContainer)targetSchema, augmentSchema);
@@ -348,7 +346,7 @@ public final class SchemaUtils {
             if (child instanceof AugmentationNode
                     && belongsToCaseAugment(choiceCaseNode, (AugmentationIdentifier) child.getIdentifier())) {
                 return Optional.of(choiceCaseNode);
-            } else if (choiceCaseNode.getDataChildByName(child.getNodeType()) != null) {
+            } else if (choiceCaseNode.findDataChildByName(child.getNodeType()).isPresent()) {
                 return Optional.of(choiceCaseNode);
             }
         }
@@ -388,27 +386,14 @@ public final class SchemaUtils {
         }
 
         for (final AugmentationSchemaNode augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
-            final DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName());
-            if (childInAugmentation != null) {
+            final Optional<DataSchemaNode> childInAugmentation = augmentation.findDataChildByName(child.getQName());
+            if (childInAugmentation.isPresent()) {
                 return augmentation;
             }
         }
         return null;
     }
 
-    /**
-     * Create AugmentationIdentifier from an AugmentationSchemaNode.
-     *
-     * @param schema Augmentation schema
-     * @return AugmentationIdentifier for the schema
-     * @throws NullPointerException if {@code schema} is null
-     * @deprecated Use {@link DataSchemaContextNode#augmentationIdentifierFrom(AugmentationSchemaNode)} instead.
-     */
-    @Deprecated
-    public static AugmentationIdentifier getNodeIdentifierForAugmentation(final AugmentationSchemaNode schema) {
-        return DataSchemaContextNode.augmentationIdentifierFrom(schema);
-    }
-
     /**
      * Finds schema node for given path in schema context. This method performs
      * lookup in the namespace of all leafs, leaf-lists, lists, containers,