Minor code cleanups 16/75916/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 10 Sep 2018 09:43:07 +0000 (11:43 +0200)
committerRobert Varga <nite@hq.sk>
Mon, 10 Sep 2018 10:23:06 +0000 (10:23 +0000)
- static private method
- reduce use of ChoiceSchemaNode.getCaseNodeByName()
- QNameWithPredicateBuilder(QName)

Change-Id: I9cf97ba4c6ef667e39212f511e17bb18b4002bc3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit ef795628f150556ddc8c93b865d1c3c0b9b0109c)

yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefPathParserListenerImpl.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefUtils.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/QNameWithPredicateBuilder.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/LeafInterner.java

index 5356a59609d3cd48129eb6789146b1afbca8ae36..078abd2067fba0bbf901f0514f6112bc59604842 100644 (file)
@@ -179,7 +179,7 @@ final class LeafRefPathParserListenerImpl extends LeafRefPathParserBaseListener
         return schemaContext.findModule(moduleName, revision).map(Module::getQNameModule);
     }
 
-    private ModuleImport getModuleImport(final Module targetModule, final String prefix) {
+    private static ModuleImport getModuleImport(final Module targetModule, final String prefix) {
         return targetModule.getImports().stream()
             .filter(imp -> prefix.equals(imp.getPrefix())).findFirst().orElse(null);
     }
index 3f7e41c0d0511f2a112a22e8d296e9fbd245b228..1248d253ecd01d12a97f5f50472088132135fde7 100644 (file)
@@ -36,7 +36,6 @@ public final class LeafRefUtils {
     public static LeafRefPath createAbsoluteLeafRefPath(
             final LeafRefPath leafRefPath, final SchemaPath contextNodeSchemaPath,
             final Module module) {
-
         if (leafRefPath.isAbsolute()) {
             return leafRefPath;
         }
@@ -57,50 +56,34 @@ public final class LeafRefUtils {
         return LeafRefPath.create(absoluteLeafRefTargetPathList, true);
     }
 
-    private static Deque<QNameWithPredicate> schemaPathToXPathQNames(
-            final SchemaPath nodePath, final Module module) {
-
+    private static Deque<QNameWithPredicate> schemaPathToXPathQNames(final SchemaPath nodePath, final Module module) {
         final Deque<QNameWithPredicate> xpath = new LinkedList<>();
-
-        final Iterator<QName> nodePathIterator = nodePath.getPathFromRoot()
-                .iterator();
+        final Iterator<QName> nodePathIterator = nodePath.getPathFromRoot().iterator();
 
         DataNodeContainer currenDataNodeContainer = module;
         while (nodePathIterator.hasNext()) {
             final QName qname = nodePathIterator.next();
-            final DataSchemaNode child = currenDataNodeContainer
-                    .getDataChildByName(qname);
+            final DataSchemaNode child = currenDataNodeContainer.getDataChildByName(qname);
 
             if (child instanceof DataNodeContainer) {
                 if (!(child instanceof CaseSchemaNode)) {
-                    final QNameWithPredicate newQName = new QNameWithPredicateBuilder(
-                            qname.getModule(), qname.getLocalName()).build();
-                    xpath.add(newQName);
+                    xpath.add(new QNameWithPredicateBuilder(qname).build());
                 }
                 currenDataNodeContainer = (DataNodeContainer) child;
             } else if (child instanceof ChoiceSchemaNode) {
                 if (nodePathIterator.hasNext()) {
-                    currenDataNodeContainer = ((ChoiceSchemaNode) child)
-                            .getCaseNodeByName(nodePathIterator.next());
+                    currenDataNodeContainer = ((ChoiceSchemaNode) child).getCases().get(nodePathIterator.next());
                 } else {
                     break;
                 }
-            } else if (child instanceof LeafSchemaNode
-                    || child instanceof LeafListSchemaNode) {
-
-                final QNameWithPredicate newQName = new QNameWithPredicateBuilder(
-                        qname.getModule(), qname.getLocalName()).build();
-                xpath.add(newQName);
+            } else if (child instanceof LeafSchemaNode || child instanceof LeafListSchemaNode) {
+                xpath.add(new QNameWithPredicateBuilder(qname).build());
                 break;
-
             } else if (child == null) {
-                throw new IllegalArgumentException("No child " + qname
-                        + " found in node container " + currenDataNodeContainer
-                        + " in module " + module.getName());
+                throw new IllegalArgumentException("No child " + qname + " found in node container "
+                        + currenDataNodeContainer + " in module " + module.getName());
             } else {
-                throw new IllegalStateException(
-                        "Illegal schema node type in the path: "
-                                + child.getClass());
+                throw new IllegalStateException("Illegal schema node type in the path: " + child.getClass());
             }
         }
 
index 5bc260d761f162daad8356a78a93f7a7e3d0d568..638dcff52f308e8781fde875f9548bec40dd20f4 100644 (file)
@@ -11,6 +11,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 
 class QNameWithPredicateBuilder implements Builder<QNameWithPredicate> {
@@ -26,6 +27,10 @@ class QNameWithPredicateBuilder implements Builder<QNameWithPredicate> {
         }
     };
 
+    QNameWithPredicateBuilder(final QName qname) {
+        this(qname.getModule(), qname.getLocalName());
+    }
+
     QNameWithPredicateBuilder(final QNameModule moduleQname, final String localName) {
         this.moduleQname = moduleQname;
         this.localName = localName;
index 6bd8c4e70774a9687fadcae30fcf6968eb3e9c11..f0afe4263f978b3fc91efa8ba4ac0da2577ebe18 100644 (file)
@@ -461,7 +461,7 @@ public final class SchemaUtils {
             return child;
         }
         if (node instanceof ChoiceSchemaNode) {
-            return ((ChoiceSchemaNode) node).getCaseNodeByName(qname);
+            return ((ChoiceSchemaNode) node).getCases().get(qname);
         }
         if (node instanceof OperationDefinition) {
             switch (qname.getLocalName()) {
index 85a47bdbd71a9753318116dadc45f00c76086e71..bb5eea153d1ed3da94337c3fe9430d353f917bd1 100644 (file)
@@ -51,10 +51,10 @@ public final class LeafInterner {
             final T ret = (T) INTERNER.intern(sample);
             LOG.trace("Interned object {} to {}", sample, ret);
             return ret;
-        } else {
-            // Non-empty attributes, do not intern
-            return sample;
         }
+
+        // Non-empty attributes, do not intern
+        return sample;
     }
 
     /**