Do not use Optional in NormalizedNodeWrapper 49/81249/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Mar 2019 09:58:49 +0000 (10:58 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Mar 2019 11:02:24 +0000 (12:02 +0100)
Use nullable schema instead, as the caller is package-private and
ends up unpacking the return anyway. This simplifies
NormalizedNodePruner a bit.

JIRA: CONTROLLER-1887
Change-Id: I395dd8266bd7198f66890c4ae3633ecda9281726
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/NormalizedNodeBuilderWrapper.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/NormalizedNodePruner.java

index e39e012..726f69e 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.controller.cluster.datastore.node.utils.transformer;
 
-import com.google.common.base.Optional;
+import static java.util.Objects.requireNonNull;
+
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
@@ -16,12 +18,12 @@ import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
 final class NormalizedNodeBuilderWrapper {
     private final NormalizedNodeContainerBuilder<?, ?, ?, ?> builder;
     private final PathArgument identifier;
-    private final Optional<DataSchemaContextNode<?>> schemaNode;
+    private final DataSchemaContextNode<?> schemaNode;
 
     NormalizedNodeBuilderWrapper(final NormalizedNodeContainerBuilder<?, ?, ?, ?> builder,
-            final PathArgument identifier, final Optional<DataSchemaContextNode<?>> schemaNode) {
-        this.builder = builder;
-        this.identifier = identifier;
+            final PathArgument identifier, final @Nullable DataSchemaContextNode<?> schemaNode) {
+        this.builder = requireNonNull(builder);
+        this.identifier = requireNonNull(identifier);
         this.schemaNode = schemaNode;
     }
 
@@ -38,7 +40,7 @@ final class NormalizedNodeBuilderWrapper {
         return identifier;
     }
 
-    Optional<DataSchemaContextNode<?>> getSchema() {
+    @Nullable DataSchemaContextNode<?> getSchema() {
         return schemaNode;
     }
 }
index ecbaf1b..cacef95 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.controller.cluster.datastore.node.utils.transformer;
 
 import static com.google.common.base.Preconditions.checkState;
 
-import com.google.common.base.Optional;
 import java.net.URI;
 import java.util.ArrayDeque;
 import java.util.Deque;
@@ -198,7 +197,7 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
             throw new IllegalStateException("endNode called on an empty stack", e);
         }
 
-        if (!child.getSchema().isPresent()) {
+        if (child.getSchema() == null) {
             LOG.debug("Schema not found for {}", child.identifier());
             return;
         }
@@ -232,7 +231,8 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
     }
 
     private static boolean hasValidSchema(final QName name, final NormalizedNodeBuilderWrapper parent) {
-        boolean valid = parent.getSchema().isPresent() && parent.getSchema().get().getChild(name) != null;
+        final DataSchemaContextNode<?> parentSchema = parent.getSchema();
+        final boolean valid = parentSchema != null && parentSchema.getChild(name) != null;
         if (!valid) {
             LOG.debug("Schema not found for {}", name);
         }
@@ -242,14 +242,13 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
 
     private NormalizedNodeBuilderWrapper addBuilder(final NormalizedNodeContainerBuilder<?, ?, ?, ?> builder,
             final PathArgument identifier) {
-        final Optional<DataSchemaContextNode<?>> schemaNode;
-        NormalizedNodeBuilderWrapper parent = stack.peek();
-        if (parent == null) {
-            schemaNode = Optional.fromNullable(nodePathSchemaNode);
-        } else if (parent.getSchema().isPresent()) {
-            schemaNode = Optional.fromNullable(parent.getSchema().get().getChild(identifier));
+        final DataSchemaContextNode<?> schemaNode;
+        final NormalizedNodeBuilderWrapper parent = stack.peek();
+        if (parent != null) {
+            final DataSchemaContextNode<?> parentSchema = parent.getSchema();
+            schemaNode = parentSchema == null ? null : parentSchema.getChild(identifier);
         } else {
-            schemaNode = Optional.absent();
+            schemaNode = nodePathSchemaNode;
         }
 
         NormalizedNodeBuilderWrapper wrapper = new NormalizedNodeBuilderWrapper(builder, identifier, schemaNode);

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.