Reduce use of getChildByName() 49/81449/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Apr 2019 18:34:12 +0000 (20:34 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Apr 2019 21:46:35 +0000 (23:46 +0200)
This reduces the number of warnings and also the number of required
assertions.

Change-Id: I96456a15ec817b6335572fd373d117af887dd38b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
20 files changed:
yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java
yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java
yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/AnyXmlWithParamsParsingTest.java
yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug5396Test.java
yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8083Test.java
yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8675Test.java
yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/StrictParsingModeTest.java
yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/YangModeledAnyXMLDeserializationTest.java
yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/YangModeledAnyXMLSerializationTest.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/SchemaTracker.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodes.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringPatternCheckingCodecTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest2.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest3.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java

index 50c8bd0bedd5f6dff003551e8b471a6b701c70f6..c0f652f246db6372a72e18a266e6fa8569f0071e 100644 (file)
@@ -200,7 +200,7 @@ public class JsonStreamToNormalizedNodeTest {
 
         final NormalizedNodeResult result = new NormalizedNodeResult();
         final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
-        final SchemaNode parentNode = schemaContext.getDataChildByName(CONT_1);
+        final SchemaNode parentNode = schemaContext.findDataChildByName(CONT_1).get();
         final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
             JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext), parentNode);
         jsonParser.parse(new JsonReader(new StringReader(inputJson)));
@@ -214,7 +214,7 @@ public class JsonStreamToNormalizedNodeTest {
 
         final NormalizedNodeResult result = new NormalizedNodeResult();
         final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
-        final SchemaNode parentNode = schemaContext.getDataChildByName(CONT_1);
+        final SchemaNode parentNode = schemaContext.findDataChildByName(CONT_1).get();
         final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
             JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext), parentNode);
         jsonParser.parse(new JsonReader(new StringReader(inputJson)));
@@ -228,7 +228,7 @@ public class JsonStreamToNormalizedNodeTest {
 
         final NormalizedNodeResult result = new NormalizedNodeResult();
         final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
-        final SchemaNode parentNode = schemaContext.getDataChildByName(CONT_1);
+        final SchemaNode parentNode = schemaContext.findDataChildByName(CONT_1).get();
 
         final QName augmentChoice1QName = QName.create(parentNode.getQName(), "augment-choice1");
         final QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2");
index 43632532ed64ad4737f6ad0b0eb5b576256f0883..ab6f3c0ea464df8c5fbb7d9bea1e0284d48dedc0 100644 (file)
@@ -57,9 +57,8 @@ public class YangModeledAnyXmlSupportTest {
             SAXException {
         schemaContext = YangParserTestUtils.parseYangResourceDirectory("/yang-modeled-anyxml/yang");
         final Module bazModule = schemaContext.findModules("baz").iterator().next();
-        final ContainerSchemaNode bazCont = (ContainerSchemaNode) bazModule.getDataChildByName(
-                QName.create(bazModule.getQNameModule(), "baz"));
-        assertNotNull(bazCont);
+        final ContainerSchemaNode bazCont = (ContainerSchemaNode) bazModule.findDataChildByName(
+                QName.create(bazModule.getQNameModule(), "baz")).get();
 
         final InputStream resourceAsStream = YangModeledAnyXmlSupportTest.class.getResourceAsStream(
                 "/yang-modeled-anyxml/xml/baz.xml");
index d4df12623bf5ad266315564cfdc26808ddc3cbb3..9089df140e645efdcace96ea8b1d9d36144e0c01 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.yangtools.yang.data.codec.xml;
 
 import static org.hamcrest.CoreMatchers.containsString;
@@ -23,7 +22,8 @@ import javax.xml.transform.stream.StreamResult;
 import org.junit.Test;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.QName;
-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.PathArgument;
 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;
@@ -63,7 +63,7 @@ public class AnyXmlWithParamsParsingTest {
         xmlParser.traverse(new DOMSource(doc.getDocumentElement()));
         final NormalizedNode<?, ?> parsed = resultHolder.getResult();
 
-        final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> editCfg = ((ContainerNode) parsed)
+        final DataContainerChild<? extends PathArgument, ?> editCfg = ((ContainerNode) parsed)
                 .getChild(getNodeId(parsed, "edit-content")).get();
 
         final DOMSource anyXmlParsedDom = ((AnyXmlNode) ((ChoiceNode) editCfg)
@@ -83,8 +83,8 @@ public class AnyXmlWithParamsParsingTest {
                 "interface-configurations xmlns=\"http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg\""));
     }
 
-    private YangInstanceIdentifier.NodeIdentifier getNodeId(final NormalizedNode<?, ?> parsed, final String localName) {
-        return new YangInstanceIdentifier.NodeIdentifier(QName.create(parsed.getNodeType(), localName));
+    private static NodeIdentifier getNodeId(final NormalizedNode<?, ?> parsed, final String localName) {
+        return new NodeIdentifier(QName.create(parsed.getNodeType(), localName));
     }
 
     private static String toStringDom(final DOMSource source) {
index a8c373d1e0827f684e96ba17d09bfe521f7df990..c26c2d69cd985c00f7c62a7c0ca7d4f2cea68c5d 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.yangtools.yang.data.codec.xml;
 
 import static org.junit.Assert.assertEquals;
@@ -66,9 +65,8 @@ public class Bug5396Test {
     private void testInputXML(final String xmlPath, final String expectedValue) throws Exception {
         final InputStream resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream(xmlPath);
         final Module fooModule = schemaContext.getModules().iterator().next();
-        final ContainerSchemaNode rootCont = (ContainerSchemaNode) fooModule.getDataChildByName(
-                QName.create(fooModule.getQNameModule(), "root"));
-        assertNotNull(rootCont);
+        final ContainerSchemaNode rootCont = (ContainerSchemaNode) fooModule.findDataChildByName(
+                QName.create(fooModule.getQNameModule(), "root")).get();
 
         final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
 
index 555ac8f415faf71c265ee3763652227456db28e5..7d8606ab73c58a50447dddb459df32d14880cb8e 100644 (file)
@@ -30,9 +30,8 @@ public class Bug8083Test {
     public void testInstanceIdentifierPathWithEmptyListKey() throws Exception {
         final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/baz.yang");
         final Module bazModule = schemaContext.getModules().iterator().next();
-        final ContainerSchemaNode topCont = (ContainerSchemaNode) bazModule.getDataChildByName(
-                QName.create(bazModule.getQNameModule(), "top-cont"));
-        assertNotNull(topCont);
+        final ContainerSchemaNode topCont = (ContainerSchemaNode) bazModule.findDataChildByName(
+                QName.create(bazModule.getQNameModule(), "top-cont")).get();
 
         final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/baz.xml");
 
@@ -51,9 +50,8 @@ public class Bug8083Test {
     public void testInstanceIdentifierPathWithIdentityrefListKey() throws Exception {
         final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/zab.yang");
         final Module zabModule = schemaContext.getModules().iterator().next();
-        final ContainerSchemaNode topCont = (ContainerSchemaNode) zabModule.getDataChildByName(
-                QName.create(zabModule.getQNameModule(), "top-cont"));
-        assertNotNull(topCont);
+        final ContainerSchemaNode topCont = (ContainerSchemaNode) zabModule.findDataChildByName(
+                QName.create(zabModule.getQNameModule(), "top-cont")).get();
 
         final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/zab.xml");
 
@@ -72,9 +70,8 @@ public class Bug8083Test {
     public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws Exception {
         final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/foobar.yang");
         final Module foobarModule = schemaContext.getModules().iterator().next();
-        final ContainerSchemaNode topCont = (ContainerSchemaNode) foobarModule.getDataChildByName(
-                QName.create(foobarModule.getQNameModule(), "top-cont"));
-        assertNotNull(topCont);
+        final ContainerSchemaNode topCont = (ContainerSchemaNode) foobarModule.findDataChildByName(
+                QName.create(foobarModule.getQNameModule(), "top-cont")).get();
 
         final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/foobar.xml");
 
index a177ab9f778ca0431f6dedf8617b47a14ebf5faf..cd4ef6dd772a98003f376d9e80152a72ff8c297e 100644 (file)
@@ -49,9 +49,8 @@ public class Bug8675Test {
 
     @Test
     public void testParsingEmptyElements() throws Exception {
-        final ContainerSchemaNode topLevelContainer = (ContainerSchemaNode) fooModule.getDataChildByName(
-                QName.create(fooModule.getQNameModule(), "top-level-container"));
-        assertNotNull(topLevelContainer);
+        final ContainerSchemaNode topLevelContainer = (ContainerSchemaNode) fooModule.findDataChildByName(
+                QName.create(fooModule.getQNameModule(), "top-level-container")).get();
 
         final InputStream resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream(
                 "/bug8675/foo.xml");
@@ -70,9 +69,8 @@ public class Bug8675Test {
 
     @Test
     public void testParsingEmptyRootElement() throws Exception {
-        final ContainerSchemaNode topLevelContainer = (ContainerSchemaNode) fooModule.getDataChildByName(
-                QName.create(fooModule.getQNameModule(), "top-level-container"));
-        assertNotNull(topLevelContainer);
+        final ContainerSchemaNode topLevelContainer = (ContainerSchemaNode) fooModule.findDataChildByName(
+                QName.create(fooModule.getQNameModule(), "top-level-container")).get();
 
         final InputStream resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream(
                 "/bug8675/foo-2.xml");
@@ -91,9 +89,8 @@ public class Bug8675Test {
 
     @Test
     public void testListAsRootElement() throws Exception {
-        final ListSchemaNode topLevelList = (ListSchemaNode) fooModule.getDataChildByName(
-                QName.create(fooModule.getQNameModule(), "top-level-list"));
-        assertNotNull(topLevelList);
+        final ListSchemaNode topLevelList = (ListSchemaNode) fooModule.findDataChildByName(
+                QName.create(fooModule.getQNameModule(), "top-level-list")).get();
 
         final InputStream resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/bug8675/foo-3.xml");
 
@@ -111,9 +108,8 @@ public class Bug8675Test {
 
     @Test
     public void testAnyXmlAsRootElement() throws Exception {
-        final AnyXmlSchemaNode topLevelAnyXml = (AnyXmlSchemaNode) fooModule.getDataChildByName(
-                QName.create(fooModule.getQNameModule(), "top-level-anyxml"));
-        assertNotNull(topLevelAnyXml);
+        final AnyXmlSchemaNode topLevelAnyXml = (AnyXmlSchemaNode) fooModule.findDataChildByName(
+                QName.create(fooModule.getQNameModule(), "top-level-anyxml")).get();
 
         final InputStream resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/bug8675/foo-4.xml");
 
@@ -131,8 +127,8 @@ public class Bug8675Test {
 
     @Test
     public void testLeafAsRootElement() throws Exception {
-        final LeafSchemaNode topLevelLeaf = (LeafSchemaNode) fooModule.getDataChildByName(
-                QName.create(fooModule.getQNameModule(), "top-level-leaf"));
+        final LeafSchemaNode topLevelLeaf = (LeafSchemaNode) fooModule.findDataChildByName(
+                QName.create(fooModule.getQNameModule(), "top-level-leaf")).get();
 
         final InputStream resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/bug8675/foo-5.xml");
 
@@ -150,8 +146,8 @@ public class Bug8675Test {
 
     @Test
     public void testLeafListAsRootElement() throws Exception {
-        final LeafListSchemaNode topLevelLeafList = (LeafListSchemaNode) fooModule.getDataChildByName(
-                QName.create(fooModule.getQNameModule(), "top-level-leaf-list"));
+        final LeafListSchemaNode topLevelLeafList = (LeafListSchemaNode) fooModule.findDataChildByName(
+                QName.create(fooModule.getQNameModule(), "top-level-leaf-list")).get();
 
         final InputStream resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/bug8675/foo-6.xml");
 
index 8d9ebf61da6811ee96263c88fff328745680958d..e49aad3aad982bba67b015d4db09d105462ce96d 100644 (file)
@@ -34,9 +34,8 @@ public class StrictParsingModeTest {
         final SchemaContext schemaContext = YangParserTestUtils.parseYangResource(
                 "/strict-parsing-mode-test/foo.yang");
         final Module fooModule = schemaContext.getModules().iterator().next();
-        final ContainerSchemaNode topLevelContainer = (ContainerSchemaNode) fooModule.getDataChildByName(
-                QName.create(fooModule.getQNameModule(),
-                "top-level-container"));
+        final ContainerSchemaNode topLevelContainer = (ContainerSchemaNode) fooModule.findDataChildByName(
+                QName.create(fooModule.getQNameModule(), "top-level-container")).get();
 
         final InputStream resourceAsStream = StrictParsingModeTest.class.getResourceAsStream(
                 "/strict-parsing-mode-test/foo.xml");
@@ -60,8 +59,8 @@ public class StrictParsingModeTest {
         final SchemaContext schemaContext = YangParserTestUtils.parseYangResource(
                 "/strict-parsing-mode-test/foo.yang");
         final Module fooModule = schemaContext.getModules().iterator().next();
-        final ContainerSchemaNode topLevelContainer = (ContainerSchemaNode) fooModule.getDataChildByName(
-                QName.create(fooModule.getQNameModule(), "top-level-container"));
+        final ContainerSchemaNode topLevelContainer = (ContainerSchemaNode) fooModule.findDataChildByName(
+                QName.create(fooModule.getQNameModule(), "top-level-container")).get();
 
         final InputStream resourceAsStream = StrictParsingModeTest.class.getResourceAsStream(
                 "/strict-parsing-mode-test/foo.xml");
index 5a8bbda5e22130cfac755dc29c3f4fc7a5bcfb2e..c41876f9b07979ace9ffef2ca5df82656a023cea 100644 (file)
@@ -75,7 +75,7 @@ public class YangModeledAnyXMLDeserializationTest {
 
     @Test
     public void testRawAnyXMLFromBar() throws Exception {
-        DataSchemaNode barContainer = schemaContext.getDataChildByName(QName.create(barModuleQName, "bar"));
+        DataSchemaNode barContainer = schemaContext.findDataChildByName(QName.create(barModuleQName, "bar")).get();
         assertTrue(barContainer instanceof ContainerSchemaNode);
         final YangModeledAnyXmlSchemaNode yangModeledAnyXML = new YangModeledAnyXMLSchemaNodeImplTest(myAnyXMLDataBar,
                 (ContainerSchemaNode) barContainer);
@@ -117,8 +117,8 @@ public class YangModeledAnyXMLDeserializationTest {
         final InputStream resourceAsStream = YangModeledAnyXMLDeserializationTest.class.getResourceAsStream(
                 "/anyxml-support/xml/foo.xml");
         final Module foo = schemaContext.findModules("foo").iterator().next();
-        final YangModeledAnyXmlSchemaNode myAnyXmlData = (YangModeledAnyXmlSchemaNode) foo.getDataChildByName(
-                QName.create(foo.getQNameModule(), "my-anyxml-data"));
+        final YangModeledAnyXmlSchemaNode myAnyXmlData = (YangModeledAnyXmlSchemaNode) foo.findDataChildByName(
+                QName.create(foo.getQNameModule(), "my-anyxml-data")).get();
 
         final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
         final NormalizedNodeResult result = new NormalizedNodeResult();
@@ -133,7 +133,7 @@ public class YangModeledAnyXMLDeserializationTest {
         final YangModeledAnyXmlNode yangModeledAnyXmlNode = (YangModeledAnyXmlNode) output;
 
         DataSchemaNode schemaOfAnyXmlData = yangModeledAnyXmlNode.getSchemaOfAnyXmlData();
-        DataSchemaNode expectedSchemaOfAnyXmlData = schemaContext.getDataChildByName(myContainer2);
+        DataSchemaNode expectedSchemaOfAnyXmlData = schemaContext.findDataChildByName(myContainer2).get();
         assertEquals(expectedSchemaOfAnyXmlData, schemaOfAnyXmlData);
 
         Collection<DataContainerChild<? extends PathArgument, ?>> value = yangModeledAnyXmlNode.getValue();
index 777013880603b3649d6b281b215a9aa9ae60dd21..cb521449d0f0c1ecf0c7154bcfe1bfa5f65650d4 100644 (file)
@@ -94,9 +94,8 @@ public class YangModeledAnyXMLSerializationTest extends XMLTestCase {
         final InputStream resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream(
                 "/anyxml-support/serialization/baz.xml");
         final Module bazModule = SCHEMA_CONTEXT.findModules("baz").iterator().next();
-        final ContainerSchemaNode bazCont = (ContainerSchemaNode) bazModule.getDataChildByName(
-                QName.create(bazModule.getQNameModule(), "baz"));
-        assertNotNull(bazCont);
+        final ContainerSchemaNode bazCont = (ContainerSchemaNode) bazModule.findDataChildByName(
+                QName.create(bazModule.getQNameModule(), "baz")).get();
 
         final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
 
index 00ad5a04965642475a815043435ef1e4fcaac881..d0475b64cc81b7c0714cac33828d0ae2c8b1b535 100644 (file)
@@ -124,27 +124,23 @@ public final class SchemaTracker {
     }
 
     private static SchemaNode findChildInCases(final ChoiceSchemaNode parent, final QName qname) {
-        DataSchemaNode schema = null;
         for (final CaseSchemaNode caze : parent.getCases().values()) {
-            final DataSchemaNode potential = caze.getDataChildByName(qname);
-            if (potential != null) {
-                schema = potential;
-                break;
+            final Optional<DataSchemaNode> potential = caze.findDataChildByName(qname);
+            if (potential.isPresent()) {
+                return potential.get();
             }
         }
-        return schema;
+        return null;
     }
 
     private static SchemaNode findCaseByChild(final ChoiceSchemaNode parent, final QName qname) {
-        DataSchemaNode schema = null;
         for (final CaseSchemaNode caze : parent.getCases().values()) {
-            final DataSchemaNode potential = caze.getDataChildByName(qname);
-            if (potential != null) {
-                schema = caze;
-                break;
+            final Optional<DataSchemaNode> potential = caze.findDataChildByName(qname);
+            if (potential.isPresent()) {
+                return caze;
             }
         }
-        return schema;
+        return null;
     }
 
     public void startList(final PathArgument name) {
index 8b65d4628919631e16295ef8031b8c3eca8aec11..1eca9b8417f7a2310807fa070c271f400d41069d 100644 (file)
@@ -130,11 +130,9 @@ abstract class InstanceIdToNodes<T extends PathArgument> implements Identifiable
     }
 
     private static Optional<DataSchemaNode> findChildSchemaNode(final DataNodeContainer parent, final QName child) {
-        DataSchemaNode potential = parent.getDataChildByName(child);
-        if (potential == null) {
-            potential = findChoice(Iterables.filter(parent.getChildNodes(), ChoiceSchemaNode.class), child);
-        }
-        return Optional.ofNullable(potential);
+        final Optional<DataSchemaNode> potential = parent.findDataChildByName(child);
+        return potential.isPresent() ? potential : Optional.ofNullable(
+            findChoice(Iterables.filter(parent.getChildNodes(), ChoiceSchemaNode.class), child));
     }
 
     static InstanceIdToNodes<?> fromSchemaAndQNameChecked(final DataNodeContainer schema, final QName child) {
@@ -173,8 +171,8 @@ abstract class InstanceIdToNodes<T extends PathArgument> implements Identifiable
     private static InstanceIdToNodes<?> fromAugmentation(final DataNodeContainer parent,
             final AugmentationTarget parentAug, final DataSchemaNode child) {
         for (final AugmentationSchemaNode aug : parentAug.getAvailableAugmentations()) {
-            final DataSchemaNode potential = aug.getDataChildByName(child.getQName());
-            if (potential != null) {
+            final Optional<DataSchemaNode> potential = aug.findDataChildByName(child.getQName());
+            if (potential.isPresent()) {
                 return new InstanceIdToCompositeNodes.AugmentationNormalization(aug, parent);
             }
         }
index 1da4112ba428b04c4fee53e0afbdb410eecfc91b..9747829b393cfc7c777546a486d0714e2137fb0c 100644 (file)
@@ -65,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()) {
@@ -92,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,
@@ -202,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;
             }
         }
@@ -346,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);
             }
         }
@@ -386,8 +386,8 @@ 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;
             }
         }
index e1e6ef7c57de5e7da700eb044d4779529c988198..5922e6bf1d881b1f92ca447daa6efcbaab5946f0 100644 (file)
@@ -38,13 +38,11 @@ public class StringPatternCheckingCodecTest {
         final QNameModule testModuleQName = QNameModule.create(URI.create("string-pattern-checking-codec-test"));
 
         final Module testModule = schemaContext.findModules("string-pattern-checking-codec-test").iterator().next();
-        final ContainerSchemaNode testContainer = (ContainerSchemaNode) testModule.getDataChildByName(
-                QName.create(testModuleQName, "test-container"));
-        assertNotNull(testContainer);
+        final ContainerSchemaNode testContainer = (ContainerSchemaNode) testModule.findDataChildByName(
+                QName.create(testModuleQName, "test-container")).get();
 
-        final LeafSchemaNode testLeaf = (LeafSchemaNode) testContainer.getDataChildByName(
-                QName.create(testModuleQName, "string-leaf-with-valid-pattern"));
-        assertNotNull(testLeaf);
+        final LeafSchemaNode testLeaf = (LeafSchemaNode) testContainer.findDataChildByName(
+                QName.create(testModuleQName, "string-leaf-with-valid-pattern")).get();
 
         final StringCodec<String> codec = getCodec(testLeaf.getType(), StringCodec.class);
         assertNotNull(codec);
index b558bb964bbbc0b32ffe66a5d47cddb8b1a7fad0..624e8f343fdd4f126a252f882c8411e9d09d32f3 100644 (file)
@@ -152,8 +152,8 @@ public class DataTreeCandidateValidatorTest {
         final DataTreeModification initialDataTreeModification = inMemoryDataTree
                 .takeSnapshot().newModification();
 
-        final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule
-                .getDataChildByName(odl);
+        final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
+                .get();
 
         final ContainerNode odlProjectContainer = createOdlContainer(odlProjContSchemaNode);
 
@@ -192,7 +192,7 @@ public class DataTreeCandidateValidatorTest {
     private static void writeContributors() {
 
         final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
-                .getDataChildByName(odlContributor);
+                .findDataChildByName(odlContributor).get();
 
         final ContainerNode contributorContainer = createBasicContributorContainer(contributorContSchemaNode);
 
@@ -289,10 +289,10 @@ public class DataTreeCandidateValidatorTest {
         final YangInstanceIdentifier newOdlProjectMapEntryPath = YangInstanceIdentifier
                 .of(odl).node(project).node(mapEntryPath);
 
-        final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule
-                .getDataChildByName(odl);
-        final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode
-                .getDataChildByName(project);
+        final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
+                .get();
+        final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode.findDataChildByName(project)
+                .get();
         final MapEntryNode newProjectMapEntry = createProjectListEntry(
                 "New Project", "New Project description ...",
                 "Leader of New Project", "Owner of New Project",
@@ -335,7 +335,7 @@ public class DataTreeCandidateValidatorTest {
     private static void write() {
 
         final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
-                .getDataChildByName(odlContributor);
+                .findDataChildByName(odlContributor).get();
 
         final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode);
 
@@ -382,10 +382,8 @@ public class DataTreeCandidateValidatorTest {
 
     private static void write2() {
 
-        final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule
-                .getDataChildByName(odl);
-        final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon
-                .getDataChildByName(con1);
+        final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule.findDataChildByName(odl).get();
+        final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon.findDataChildByName(con1).get();
         final LeafNode<String> l1Leaf = ImmutableNodes.leafNode(l1, "l1 value");
         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
                 .containerBuilder(con1Con);
@@ -600,7 +598,7 @@ public class DataTreeCandidateValidatorTest {
             final ContainerSchemaNode contributorContSchemaNode) {
 
         final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
-                .getDataChildByName(contributor);
+                .findDataChildByName(contributor).get();
 
         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
                 .containerBuilder(contributorContSchemaNode);
@@ -671,14 +669,10 @@ public class DataTreeCandidateValidatorTest {
             final String odlProjectNameVal, final String odlProjectDescVal,
             final ListSchemaNode contributorListSchemaNode) {
 
-        final LeafNode<String> loginLeaf = ImmutableNodes.leafNode(login,
-                loginVal);
-        final LeafNode<String> contributorNameLeaf = ImmutableNodes.leafNode(
-                contributorName, contributorNameVal);
-        final LeafNode<String> odlProjectNameLeafRef = ImmutableNodes.leafNode(
-                odlProjectName, odlProjectNameVal);
-        final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(
-                odlProjectDesc, odlProjectDescVal);
+        final LeafNode<String> loginLeaf = ImmutableNodes.leafNode(login, loginVal);
+        final LeafNode<String> contributorNameLeaf = ImmutableNodes.leafNode(contributorName, contributorNameVal);
+        final LeafNode<String> odlProjectNameLeafRef = ImmutableNodes.leafNode(odlProjectName, odlProjectNameVal);
+        final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(odlProjectDesc, odlProjectDescVal);
 
         return Builders.mapEntryBuilder(contributorListSchemaNode)
                 .addChild(loginLeaf)
@@ -691,8 +685,7 @@ public class DataTreeCandidateValidatorTest {
     private static ContainerNode createOdlContainer(
             final ContainerSchemaNode container) {
 
-        final ListSchemaNode projListSchemaNode = (ListSchemaNode) container
-                .getDataChildByName(project);
+        final ListSchemaNode projListSchemaNode = (ListSchemaNode) container.findDataChildByName(project).get();
 
         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> odlProjectContainerBldr = Builders
                 .containerBuilder(container);
@@ -760,7 +753,7 @@ public class DataTreeCandidateValidatorTest {
             final ContainerSchemaNode contributorContSchemaNode) {
 
         final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
-                .getDataChildByName(contributor);
+                .findDataChildByName(contributor).get();
 
         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
                 .containerBuilder(contributorContSchemaNode);
index 2e2a42aad7cde2e9681e7d0fec4adbea8dfad86a..4450c8ae2c2cd12f2a2b7fde96506e32ea172573 100644 (file)
@@ -110,13 +110,14 @@ public class DataTreeCandidateValidatorTest2 {
 
         inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
         final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
-        final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule.getDataChildByName(chips);
+        final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(chips)
+                .get();
         final ContainerNode chipsContainer = createChipsContainer(chipsListContSchemaNode);
         final YangInstanceIdentifier path1 = YangInstanceIdentifier.of(chips);
         initialDataTreeModification.write(path1, chipsContainer);
 
         final ContainerSchemaNode devTypesListContSchemaNode = (ContainerSchemaNode) mainModule
-                .getDataChildByName(deviceTypeStr);
+                .findDataChildByName(deviceTypeStr).get();
         final ContainerNode deviceTypesContainer = createDevTypeStrContainer(devTypesListContSchemaNode);
         final YangInstanceIdentifier path2 = YangInstanceIdentifier.of(deviceTypeStr);
         initialDataTreeModification.write(path2, deviceTypesContainer);
@@ -144,7 +145,8 @@ public class DataTreeCandidateValidatorTest2 {
 
     private static void writeDevices() {
 
-        final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.getDataChildByName(devices);
+        final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(devices)
+                .get();
 
         final ContainerNode devicesContainer = createDevicesContainer(devicesContSchemaNode);
 
@@ -182,7 +184,7 @@ public class DataTreeCandidateValidatorTest2 {
 
     private static ContainerNode createDevTypeStrContainer(final ContainerSchemaNode container) {
 
-        final ListSchemaNode devTypeListSchemaNode = (ListSchemaNode) container.getDataChildByName(deviceType);
+        final ListSchemaNode devTypeListSchemaNode = (ListSchemaNode) container.findDataChildByName(deviceType).get();
 
         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devTypeContainerBldr = Builders
                 .containerBuilder(container);
@@ -221,7 +223,7 @@ public class DataTreeCandidateValidatorTest2 {
 
     private static ContainerNode createChipsContainer(final ContainerSchemaNode container) {
 
-        final ListSchemaNode chipsListSchemaNode = (ListSchemaNode) container.getDataChildByName(chip);
+        final ListSchemaNode chipsListSchemaNode = (ListSchemaNode) container.findDataChildByName(chip).get();
 
         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> chipsContainerBldr = Builders
                 .containerBuilder(container);
@@ -259,7 +261,7 @@ public class DataTreeCandidateValidatorTest2 {
 
     private static ContainerNode createDevicesContainer(final ContainerSchemaNode container) {
 
-        final ListSchemaNode devicesListSchemaNode = (ListSchemaNode) container.getDataChildByName(device);
+        final ListSchemaNode devicesListSchemaNode = (ListSchemaNode) container.findDataChildByName(device).get();
 
         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devicesContainerBldr = Builders
                 .containerBuilder(container);
index e03e7bbf9a7493e4b0e71cc29671e0913c3469df..ef8f4243c8bf34027f84bc6626870ec184860479 100644 (file)
@@ -120,13 +120,14 @@ public class DataTreeCandidateValidatorTest3 {
 
         final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
 
-        final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule.getDataChildByName(chips);
+        final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(chips)
+                .get();
         final ContainerNode chipsContainer = createChipsContainer(chipsListContSchemaNode);
         final YangInstanceIdentifier path1 = YangInstanceIdentifier.of(chips);
         initialDataTreeModification.write(path1, chipsContainer);
 
         final ContainerSchemaNode devTypesListContSchemaNode = (ContainerSchemaNode) mainModule
-                .getDataChildByName(deviceTypeStr);
+                .findDataChildByName(deviceTypeStr).get();
         final ContainerNode deviceTypesContainer = createDevTypeStrContainer(devTypesListContSchemaNode);
         final YangInstanceIdentifier path2 = YangInstanceIdentifier.of(deviceTypeStr);
         initialDataTreeModification.write(path2, deviceTypesContainer);
@@ -157,7 +158,8 @@ public class DataTreeCandidateValidatorTest3 {
 
     private static void writeDevices() {
 
-        final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.getDataChildByName(devices);
+        final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(devices)
+                .get();
 
         final ContainerNode devicesContainer = createDevicesContainer(devicesContSchemaNode);
 
@@ -194,7 +196,8 @@ public class DataTreeCandidateValidatorTest3 {
 
     private static void mergeDevices() {
 
-        final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.getDataChildByName(devices);
+        final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(devices)
+                .get();
 
         final ContainerNode devicesContainer = createDevices2Container(devicesContSchemaNode);
 
@@ -233,7 +236,7 @@ public class DataTreeCandidateValidatorTest3 {
 
     private static ContainerNode createDevTypeStrContainer(final ContainerSchemaNode container) {
 
-        final ListSchemaNode devTypeListSchemaNode = (ListSchemaNode) container.getDataChildByName(deviceType);
+        final ListSchemaNode devTypeListSchemaNode = (ListSchemaNode) container.findDataChildByName(deviceType).get();
 
         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devTypeContainerBldr = Builders
                 .containerBuilder(container);
@@ -279,7 +282,7 @@ public class DataTreeCandidateValidatorTest3 {
 
     private static ContainerNode createChipsContainer(final ContainerSchemaNode container) {
 
-        final ListSchemaNode chipsListSchemaNode = (ListSchemaNode) container.getDataChildByName(chip);
+        final ListSchemaNode chipsListSchemaNode = (ListSchemaNode) container.findDataChildByName(chip).get();
 
         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> chipsContainerBldr = Builders
                 .containerBuilder(container);
@@ -317,7 +320,7 @@ public class DataTreeCandidateValidatorTest3 {
 
     private static ContainerNode createDevicesContainer(final ContainerSchemaNode container) {
 
-        final ListSchemaNode devicesListSchemaNode = (ListSchemaNode) container.getDataChildByName(device);
+        final ListSchemaNode devicesListSchemaNode = (ListSchemaNode) container.findDataChildByName(device).get();
 
         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devicesContainerBldr = Builders
                 .containerBuilder(container);
@@ -346,7 +349,7 @@ public class DataTreeCandidateValidatorTest3 {
 
     private static ContainerNode createDevices2Container(final ContainerSchemaNode container) {
 
-        final ListSchemaNode devicesListSchemaNode = (ListSchemaNode) container.getDataChildByName(device);
+        final ListSchemaNode devicesListSchemaNode = (ListSchemaNode) container.findDataChildByName(device).get();
 
         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devicesContainerBldr = Builders
                 .containerBuilder(container);
index 9d2a02bebed3ce3f53bebeaa87c49d444f3292dd..5f8c1463d0182a57a091b93abf067ae5a4348f76 100644 (file)
@@ -65,10 +65,10 @@ public class LeafRefContextTest {
         final QName q5 = QName.create(root, "list1");
         final QName q6 = QName.create(root, "name");
 
-        final DataSchemaNode leafRefNode = rootMod.getDataChildByName(q1);
-        final DataSchemaNode targetNode = rootMod.getDataChildByName(q2);
-        final DataSchemaNode cont1Node = rootMod.getDataChildByName(q3);
-        final DataSchemaNode cont2Node = rootMod.getDataChildByName(q4);
+        final DataSchemaNode leafRefNode = rootMod.findDataChildByName(q1).get();
+        final DataSchemaNode targetNode = rootMod.findDataChildByName(q2).get();
+        final DataSchemaNode cont1Node = rootMod.findDataChildByName(q3).get();
+        final DataSchemaNode cont2Node = rootMod.findDataChildByName(q4).get();
         final DataSchemaNode name1Node = ((DataNodeContainer) ((DataNodeContainer) rootMod.getDataChildByName(q3))
                 .getDataChildByName(q5)).getDataChildByName(q6);
 
index 86ce040fed6af2a48e99c1203aeec9df331c6f4e..784ee08bc712d6bdcffe44c5ff7563c0b2c709a0 100644 (file)
@@ -196,16 +196,16 @@ public class LeafRefContextTreeBuilderTest {
     @Test
     public void leafRefContextUtilsTest3() {
         final QName q16 = QName.create(tst, "con1");
-        final DataSchemaNode con1 = tstMod.getDataChildByName(q16);
-        final List<LeafRefContext> allLeafRefChilds = LeafRefContextUtils
-                .findAllLeafRefChilds(con1, rootLeafRefContext);
+        final DataSchemaNode con1 = tstMod.findDataChildByName(q16).get();
+        final List<LeafRefContext> allLeafRefChilds = LeafRefContextUtils.findAllLeafRefChilds(con1,
+            rootLeafRefContext);
 
         assertNotNull(allLeafRefChilds);
         assertFalse(allLeafRefChilds.isEmpty());
         assertEquals(4, allLeafRefChilds.size());
 
         final QName q17 = QName.create(tst, "odl-contributor");
-        final DataSchemaNode odlContributorNode = tstMod.getDataChildByName(q17);
+        final DataSchemaNode odlContributorNode = tstMod.findDataChildByName(q17).get();
         List<LeafRefContext> allChildsReferencedByLeafRef = LeafRefContextUtils.findAllChildsReferencedByLeafRef(
                 odlContributorNode, rootLeafRefContext);
 
index 20a20333ae1323793b2089dd3fb045c36aec6637..4af3852aad68860210f1a98afff7ef87ba26a1f5 100644 (file)
@@ -95,9 +95,9 @@ public class BuilderTest {
                 .toURI());
         final SchemaContext schema = YangParserTestUtils.parseYangFiles(leafRefTestYang);
         final Module module = schema.getModules().iterator().next();
-        final DataSchemaNode root = module.getDataChildByName(ROOT_CONTAINER);
-        list = (ListSchemaNode)((ContainerSchemaNode) root).getDataChildByName(LIST_MAIN);
-        leafList = (LeafListSchemaNode)((ContainerSchemaNode) root).getDataChildByName(LEAF_LIST_MAIN);
+        final DataSchemaNode root = module.findDataChildByName(ROOT_CONTAINER).get();
+        list = (ListSchemaNode)((ContainerSchemaNode) root).findDataChildByName(LIST_MAIN).get();
+        leafList = (LeafListSchemaNode)((ContainerSchemaNode) root).findDataChildByName(LEAF_LIST_MAIN).get();
     }
 
     @Test
index 7cd56d9a5422ae0ef884d48ff89f616aabd6629a..90a0bc033b2d8f90db5f6aa33569bb32ffef6a78 100644 (file)
@@ -166,7 +166,7 @@ public class NormalizedDataBuilderTest {
     private static AugmentationSchemaNode getAugmentationSchemaForChild(final ContainerSchemaNode containerNode,
             final QName qname) {
         for (AugmentationSchemaNode augmentationSchema : containerNode.getAvailableAugmentations()) {
-            if (augmentationSchema.getDataChildByName(qname) != null) {
+            if (augmentationSchema.findDataChildByName(qname).isPresent()) {
                 return augmentationSchema;
             }
         }