BUG-4688: Rework SchemaContext module lookups 41/64641/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 23 Oct 2017 23:11:49 +0000 (01:11 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 24 Oct 2017 16:39:07 +0000 (18:39 +0200)
SchemaContext.findModule*() family of methods is making the mistake
of treating null revision as a wildcard. This does not match RFC6020
and RFC7950, which allow for modules without a revision, hence we need
to mark non-existing modules with a magic constant, which maps to
1970-01-01.

While we can use identity checks and assume such a revision will not
be seen in the wild, this approach does not really work with maps
and creates confusion with users, who need to treat DEFAULT_DATE_REV
as something special.

This patch cleans up the lookup methods and makes
ModuleIdentifier.getRevision() return an Optional<Date>, in preparation
to making the transition to SourceIdentifier.

As a side-effect we switch to using QNameModule-based lookups in couple
of places, which are significantly faster than combined name/revision
lookups.

Change-Id: I5602192e26d721d2461248c612d98a1b305c6958
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
90 files changed:
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/xpath/PrefixConverters.java
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/IdentityrefJSONCodec.java
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONStreamWriterContext.java
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONStringInstanceIdentifierCodec.java
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java
yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java
yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/IdentityrefXmlCodec.java
yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlStringInstanceIdentifierCodec.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/leafref/LeafRefContextBuilder.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextTreeBuilder.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefPathParserListenerImpl.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringPatternCheckingCodecTest.java
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/LeafrefXPathStringParsingPathArgumentBuilder.java
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/YangFunctionContext.java
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/ModuleStringIdentityrefCodec.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleIdentifier.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java
yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug6856Test.java
yang/yang-model-immutable/src/main/java/org/opendaylight/yangtools/yang/model/immutable/AbstractSchemaContext.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractSchemaContext.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleIdentifierImpl.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextProxyTest.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtilTest.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/IncludeStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ModuleStatementSupport.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SubmoduleStatementImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaRepositoryWithFeaturesTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ConstraintDefinitionsTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6871Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6874Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6887Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug9241Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/IdentityStatementTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/IdentityrefStatementTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/LeafrefStatementTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentProcessTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4456Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4623Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4933Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5712Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5884Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6491Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6972Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7440Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7480Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug8597Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug9005Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug9242Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug9244Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ControllerStmtParserTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeclaredStatementsTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeviationResolutionTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeviationStmtTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveBuildTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveIdentityTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveModuleTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveModulesAndSubmodulesTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveSchemaContextTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ExtensionStmtTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingAndUsesStmtTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IdentityStmtTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IfFeatureResolutionTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludedStmtsTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ListTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/MoreRevisionsTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/MustAndWhenStmtTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/NotificationStmtTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/RpcStmtTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangDataExtensionTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserWithContextTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/openconfigver/OpenconfigVersionBorderCaseTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/openconfigver/OpenconfigVersionComplexTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/openconfigver/OpenconfigVersionDefaultsTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/openconfigver/OpenconfigVersionIgnoringRevisionTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/openconfigver/OpenconfigVersionImportTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/openconfigver/OpenconfigVersionMultipleImportTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/openconfigver/OpenconfigVersionPositionTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/openconfigver/OpenconfigVersionTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/openconfigver/yin/YinOpenconfigVersionTest.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceKeyCriterion.java

index 11a9a2ed0fcd16cf3a7948584031717c8accb804..215dd9d1b325947982a5968925dc15014643dd9e 100644 (file)
@@ -15,6 +15,7 @@ import com.google.common.base.Converter;
 import com.google.common.collect.ImmutableBiMap;
 import com.google.common.collect.ImmutableBiMap.Builder;
 import com.google.common.collect.Maps;
+import java.util.Optional;
 import javax.annotation.Nonnull;
 import javax.xml.xpath.XPathExpressionException;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -49,10 +50,10 @@ public final class PrefixConverters {
         b.put(module.getPrefix(), module.getQNameModule());
 
         for (ModuleImport i : module.getImports()) {
-            final Module mod = ctx.findModuleByName(i.getModuleName(), i.getRevision());
-            checkArgument(mod != null, "Unsatisfied import of %s by module %s", i, module);
+            final Optional<Module> mod = ctx.findModule(i.getModuleName(), i.getRevision());
+            checkArgument(mod.isPresent(), "Unsatisfied import of %s by module %s", i, module);
 
-            b.put(i.getPrefix(), mod.getQNameModule());
+            b.put(i.getPrefix(), mod.get().getQNameModule());
         }
 
         return Maps.asConverter(b.build());
index d4ec3b6d9bf74f6494932372e667f99493a9d5d1..2ce042d3592f5fb3a51cea3bdf1133cd1cb6dd4a 100644 (file)
@@ -12,6 +12,7 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.gson.stream.JsonWriter;
 import java.io.IOException;
+import java.util.Iterator;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.data.util.codec.QNameCodecUtil;
@@ -39,9 +40,9 @@ final class IdentityrefJSONCodec implements JSONCodec<QName> {
                 return parentModule;
             }
 
-            final Module module = schemaContext.findModuleByName(prefix, null);
-            checkArgument(module != null, "Could not find module %s", prefix);
-            return module.getQNameModule();
+            final Iterator<Module> modules = schemaContext.findModules(prefix).iterator();
+            checkArgument(modules.hasNext(), "Could not find module %s", prefix);
+            return modules.next().getQNameModule();
         });
     }
 
@@ -54,9 +55,9 @@ final class IdentityrefJSONCodec implements JSONCodec<QName> {
     @Override
     public void writeValue(final JsonWriter writer, final QName value) throws IOException {
         final String str = QNameCodecUtil.encodeQName(value, uri -> {
-            final Module module = schemaContext.findModuleByNamespaceAndRevision(uri.getNamespace(), null);
-            checkArgument(module != null, "Cannot find module for %s", uri);
-            return module.getName();
+            final Iterator<Module> modules = schemaContext.findModules(uri.getNamespace()).iterator();
+            checkArgument(modules.hasNext(), "Cannot find module for %s", uri);
+            return modules.next().getName();
         });
         writer.value(str);
     }
index 73e428aa36d8c99a4c8c8accf872189ea77b2f00..5a3be65a1f79c30778da83410d827fcb91c42dc0 100644 (file)
@@ -12,6 +12,7 @@ import static com.google.common.base.Preconditions.checkArgument;
 import com.google.gson.stream.JsonWriter;
 import java.io.IOException;
 import java.net.URI;
+import java.util.Iterator;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.Module;
@@ -60,10 +61,10 @@ abstract class JSONStreamWriterContext {
         // Prepend module name if namespaces do not match
         final URI ns = qname.getNamespace();
         if (!ns.equals(getNamespace())) {
-            final Module module = schema.findModuleByNamespaceAndRevision(ns, null);
-            checkArgument(module != null, "Could not find module for namespace {}", ns);
+            final Iterator<Module> modules = schema.findModules(ns).iterator();
+            checkArgument(modules.hasNext(), "Could not find module for namespace {}", ns);
 
-            sb.append(module.getName());
+            sb.append(modules.next().getName());
             sb.append(':');
         }
         sb.append(qname.getLocalName());
index 03f76e5d19eb338da0a7d8c48d34ddf0af43e4db..1fed9a3201449128965a7273df6e62f48b573bc1 100644 (file)
@@ -13,6 +13,7 @@ import static java.util.Objects.requireNonNull;
 import com.google.gson.stream.JsonWriter;
 import java.io.IOException;
 import java.net.URI;
+import java.util.Iterator;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.util.AbstractModuleStringInstanceIdentifierCodec;
@@ -36,13 +37,14 @@ final class JSONStringInstanceIdentifierCodec extends AbstractModuleStringInstan
 
     @Override
     protected Module moduleForPrefix(@Nonnull final String prefix) {
-        return context.findModuleByName(prefix, null);
+        final Iterator<Module> modules = context.findModules(prefix).iterator();
+        return modules.hasNext() ? modules.next() : null;
     }
 
     @Override
     protected String prefixForNamespace(@Nonnull final URI namespace) {
-        final Module module = context.findModuleByNamespaceAndRevision(namespace, null);
-        return module == null ? null : module.getName();
+        final Iterator<Module> modules = context.findModules(namespace).iterator();
+        return modules.hasNext() ? modules.next().getName() : null;
     }
 
     @Nonnull
index 59fb571a278f03ab39a6c35cf7feff0d9492ea06..8c42de6c8884882dd872b10e1aa687fe0366b4a2 100644 (file)
@@ -27,6 +27,7 @@ import java.util.ArrayDeque;
 import java.util.Collections;
 import java.util.Deque;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Map.Entry;
 import java.util.Set;
 import javax.xml.transform.dom.DOMSource;
@@ -304,8 +305,8 @@ public final class JsonParserStream implements Closeable, Flushable {
             moduleNamePart = childName.substring(0, lastIndexOfColon);
             nodeNamePart = childName.substring(lastIndexOfColon + 1);
 
-            final Module m = schema.findModuleByName(moduleNamePart, null);
-            namespace = m == null ? null : m.getNamespace();
+            final Iterator<Module> m = schema.findModules(moduleNamePart).iterator();
+            namespace = m.hasNext() ? m.next().getNamespace() : null;
         } else {
             nodeNamePart = childName;
         }
@@ -334,7 +335,7 @@ public final class JsonParserStream implements Closeable, Flushable {
         for (final URI potentialUri : potentialUris) {
             builder.append('\n');
             //FIXME how to get information about revision from JSON input? currently first available is used.
-            builder.append(schema.findModuleByNamespace(potentialUri).iterator().next().getName());
+            builder.append(schema.findModules(potentialUri).iterator().next().getName());
         }
         return builder.toString();
     }
index 34f9661d7f225d86a4f563ca8f99ffd5082415c1..de041d6b37e19368ee8151f74c385a73fa2c472f 100644 (file)
@@ -55,7 +55,7 @@ public class YangModeledAnyXmlSupportTest {
     public static void init() throws XMLStreamException, URISyntaxException, IOException, ParserConfigurationException,
             SAXException {
         schemaContext = YangParserTestUtils.parseYangResourceDirectory("/yang-modeled-anyxml/yang");
-        final Module bazModule = schemaContext.findModuleByName("baz", null);
+        final Module bazModule = schemaContext.findModules("baz").iterator().next();
         final ContainerSchemaNode bazCont = (ContainerSchemaNode) bazModule.getDataChildByName(
                 QName.create(bazModule.getQNameModule(), "baz"));
         assertNotNull(bazCont);
index 4a0726d63247f7c5c436b33b6e04ce8b9fd0877a..dd36e738deaa06de79af438edd774ab2c853b7a6 100644 (file)
@@ -12,6 +12,7 @@ import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
 import java.net.URI;
+import java.util.Iterator;
 import java.util.Map.Entry;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.stream.XMLStreamException;
@@ -44,9 +45,9 @@ final class IdentityrefXmlCodec implements XmlCodec<QName> {
             }
 
             final String prefixedNS = ctx.getNamespaceURI(prefix);
-            final Module module = schemaContext.findModuleByNamespaceAndRevision(URI.create(prefixedNS), null);
-            checkArgument(module != null, "Could not find module for namespace %s", prefixedNS);
-            return module.getQNameModule();
+            final Iterator<Module> modules = schemaContext.findModules(URI.create(prefixedNS)).iterator();
+            checkArgument(modules.hasNext(), "Could not find module for namespace %s", prefixedNS);
+            return modules.next().getQNameModule();
         });
     }
 
index 520cd24456d0025d6bb02de99fa3dbacc6815e4a..077141632ca419088c66ec50e8847901e8915f54 100644 (file)
@@ -14,6 +14,7 @@ import static java.util.Objects.requireNonNull;
 import java.net.URI;
 import java.util.ArrayDeque;
 import java.util.Deque;
+import java.util.Iterator;
 import javax.annotation.Nonnull;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.stream.XMLStreamException;
@@ -44,13 +45,14 @@ final class XmlStringInstanceIdentifierCodec extends AbstractModuleStringInstanc
     @Override
     protected Module moduleForPrefix(@Nonnull final String prefix) {
         final String prefixedNS = getNamespaceContext().getNamespaceURI(prefix);
-        return context.findModuleByNamespaceAndRevision(URI.create(prefixedNS), null);
+        final Iterator<Module> modules = context.findModules(URI.create(prefixedNS)).iterator();
+        return modules.hasNext() ? modules.next() : null;
     }
 
     @Override
     protected String prefixForNamespace(@Nonnull final URI namespace) {
-        final Module module = context.findModuleByNamespaceAndRevision(namespace, null);
-        return module == null ? null : module.getName();
+        final Iterator<Module> modules = context.findModules(namespace).iterator();
+        return modules.hasNext() ? modules.next().getName() : null;
     }
 
     @Nonnull
index 6f7c027ba91e63522717e185839c135d0cf1f6c2..32318e981cf533b1ac7053a420a6d3e98d897635 100644 (file)
@@ -119,7 +119,7 @@ public class YangModeledAnyXMLDeserializationTest {
     public void testRealSchemaContextFromFoo() throws Exception {
         final InputStream resourceAsStream = YangModeledAnyXMLDeserializationTest.class.getResourceAsStream(
                 "/anyxml-support/xml/foo.xml");
-        final Module foo = schemaContext.findModuleByName("foo", null);
+        final Module foo = schemaContext.findModules("foo").iterator().next();
         final YangModeledAnyXmlSchemaNode myAnyXmlData = (YangModeledAnyXmlSchemaNode) foo.getDataChildByName(
                 QName.create(foo.getQNameModule(), "my-anyxml-data"));
 
index 71faa95498f3f8d487b8becb3f5fab67c58ec814..27ab3f125958926fbc015de1dc99233f1c3cc737 100644 (file)
@@ -76,7 +76,7 @@ public class YangModeledAnyXMLSerializationTest extends XMLTestCase {
     public void testSerializationOfBaz() throws Exception {
         final InputStream resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream(
                 "/anyxml-support/serialization/baz.xml");
-        final Module bazModule = schemaContext.findModuleByName("baz", null);
+        final Module bazModule = schemaContext.findModules("baz").iterator().next();
         final ContainerSchemaNode bazCont = (ContainerSchemaNode) bazModule.getDataChildByName(
                 QName.create(bazModule.getQNameModule(), "baz"));
         assertNotNull(bazCont);
index 23f585b6de64fee388db44e9214e95a27bf31099..8dfe80e22fa26ccd6bf30bb473d0d8bbd1ae9882 100644 (file)
@@ -146,14 +146,12 @@ class LeafRefContextBuilder implements Builder<LeafRefContext> {
     }
 
     public LeafRefPath getAbsoluteLeafRefTargetPath() {
-
         if (isReferencing && absoluteLeafRefTargetPath == null) {
             if (leafRefTargetPath.isAbsolute()) {
                 absoluteLeafRefTargetPath = leafRefTargetPath;
             } else {
-                absoluteLeafRefTargetPath = LeafRefUtils
-                        .createAbsoluteLeafRefPath(leafRefTargetPath,
-                                currentNodePath, getLeafRefContextModule());
+                absoluteLeafRefTargetPath = LeafRefUtils.createAbsoluteLeafRefPath(leafRefTargetPath,
+                    currentNodePath, getLeafRefContextModule());
             }
         }
 
@@ -163,8 +161,7 @@ class LeafRefContextBuilder implements Builder<LeafRefContext> {
     public Module getLeafRefContextModule() {
         final Iterator<QName> it = currentNodePath.getPathFromRoot().iterator();
         final QNameModule qnameModule = it.hasNext() ? it.next().getModule() : currentNodeQName.getModule();
-
-        return schemaContext.findModuleByNamespaceAndRevision(qnameModule.getNamespace(), qnameModule.getRevision());
+        return schemaContext.findModule(qnameModule).orElse(null);
     }
 
     public void addReferencedByLeafRefCtx(final QName qname, final LeafRefContext leafRef) {
index 89a7d3149c532c40a6a87ac5b1d1ec08f31f2280..f8265bed56cbd4df1bb011b9e785c146922c54bb 100644 (file)
@@ -16,7 +16,6 @@ import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
-import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
@@ -156,8 +155,7 @@ class LeafRefContextTreeBuilder {
         while (baseLeafRefType.getBaseType() != null) {
             baseLeafRefType = baseLeafRefType.getBaseType();
         }
-        final QNameModule module = baseLeafRefType.getQName().getModule();
-        return schemaContext.findModuleByNamespaceAndRevision(module.getNamespace(), module.getRevision());
+        return schemaContext.findModule(baseLeafRefType.getQName().getModule()).orElse(null);
     }
 
     private LeafRefContext buildLeafRefContextReferencedByTree(
index fb33abbc2c2257828f8d83762d0e4259072b714f..9ce694e7c3227b6a00bc469730f3d9672922287e 100644 (file)
@@ -165,10 +165,7 @@ final class LeafRefPathParserListenerImpl extends LeafRefPathParserBaseListener
 
     private URI getNamespaceForImportPrefix(final String prefix) {
         final ModuleImport moduleImport = getModuleImport(prefix);
-        final Module findedModule = schemaContext.findModuleByName(moduleImport.getModuleName(),
-            moduleImport.getRevision());
-
-        return findedModule.getNamespace();
+        return schemaContext.findModule(moduleImport.getModuleName(), moduleImport.getRevision()).get().getNamespace();
     }
 
     private Optional<QNameModule> getQNameModuleForImportPrefix(final String prefix) {
@@ -179,9 +176,7 @@ final class LeafRefPathParserListenerImpl extends LeafRefPathParserBaseListener
 
         final String moduleName = moduleImport.getModuleName();
         final Date revision = moduleImport.getRevision();
-        final Module foundModule = schemaContext.findModuleByName(moduleName, revision);
-
-        return Optional.of(foundModule.getQNameModule());
+        return schemaContext.findModule(moduleName, revision).map(Module::getQNameModule);
     }
 
     private ModuleImport getModuleImport(final String prefix) {
index 573665c17f5608292f3feb6e19c3b742c26d71c8..244d56bc56a00d669ff76e68121b299955f34b53 100644 (file)
@@ -44,11 +44,9 @@ public class StringPatternCheckingCodecTest {
         assertNotNull(schemaContext);
 
         final QNameModule testModuleQName = QNameModule.create(new URI("string-pattern-checking-codec-test"),
-                SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01"));
-
-        final Module testModule = schemaContext.findModuleByName("string-pattern-checking-codec-test", null);
-        assertNotNull(testModule);
+                SimpleDateFormatUtil.DEFAULT_DATE_REV);
 
+        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);
index e86890f0f40a81e84b34f0068368cdd9f21ae35a..e3c6c62f9e3043f62602ef3fd7e14a44e3c15764 100644 (file)
@@ -207,16 +207,15 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
     }
 
     private QName createQName(final String prefix, final String localName) {
-        final Module module = schemaContext.findModuleByNamespaceAndRevision(schemaNode.getQName().getNamespace(),
-                schemaNode.getQName().getRevision());
+        final Module module = schemaContext.findModule(schemaNode.getQName().getModule()).get();
         if (prefix.isEmpty() || module.getPrefix().equals(prefix)) {
             return QName.create(module.getQNameModule(), localName);
         }
 
         for (final ModuleImport moduleImport : module.getImports()) {
             if (prefix.equals(moduleImport.getPrefix())) {
-                final Module importedModule = schemaContext.findModuleByName(moduleImport.getModuleName(),
-                        moduleImport.getRevision());
+                final Module importedModule = schemaContext.findModule(moduleImport.getModuleName(),
+                        moduleImport.getRevision()).get();
                 return QName.create(importedModule.getQNameModule(),localName);
             }
         }
index 49726f0515ef87e391160d339965ff96b1b52d13..c1378b84689c4eecdb7f66b5efd8fdd3d61e4dce 100644 (file)
@@ -308,16 +308,15 @@ final class YangFunctionContext implements FunctionContext {
 
     private static IdentitySchemaNode getIdentitySchemaNodeFromQName(final QName identityQName,
             final SchemaContext schemaContext) {
-        final Module module = schemaContext.findModuleByNamespaceAndRevision(identityQName.getNamespace(),
-                identityQName.getRevision());
-        return findIdentitySchemaNodeInModule(module, identityQName);
+        final Optional<Module> module = schemaContext.findModule(identityQName.getModule());
+        Preconditions.checkArgument(module.isPresent(), "Module for %s not found", identityQName);
+        return findIdentitySchemaNodeInModule(module.get(), identityQName);
     }
 
     private static IdentitySchemaNode getIdentitySchemaNodeFromString(final String identity,
             final SchemaContext schemaContext, final TypedSchemaNode correspondingSchemaNode) {
         final List<String> identityPrefixAndName = COLON_SPLITTER.splitToList(identity);
-        final Module module = schemaContext.findModuleByNamespaceAndRevision(
-                correspondingSchemaNode.getQName().getNamespace(), correspondingSchemaNode.getQName().getRevision());
+        final Module module = schemaContext.findModule(correspondingSchemaNode.getQName().getModule()).get();
         if (identityPrefixAndName.size() == 2) {
             // prefix of local module
             if (identityPrefixAndName.get(0).equals(module.getPrefix())) {
@@ -328,8 +327,8 @@ final class YangFunctionContext implements FunctionContext {
             // prefix of imported module
             for (final ModuleImport moduleImport : module.getImports()) {
                 if (identityPrefixAndName.get(0).equals(moduleImport.getPrefix())) {
-                    final Module importedModule = schemaContext.findModuleByName(moduleImport.getModuleName(),
-                        moduleImport.getRevision());
+                    final Module importedModule = schemaContext.findModule(moduleImport.getModuleName(),
+                        moduleImport.getRevision()).get();
                     return findIdentitySchemaNodeInModule(importedModule, QName.create(
                         importedModule.getQNameModule(), identityPrefixAndName.get(1)));
                 }
index 385943908b21f385a5fbbed475349b579287d288..a7b3f23c543a8d357cdf63dfe5f6426e1b82ec79 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.yangtools.yang.data.util;
 import static java.util.Objects.requireNonNull;
 
 import java.net.URI;
+import java.util.Iterator;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.data.api.codec.IdentityrefCodec;
@@ -30,7 +31,7 @@ public abstract class ModuleStringIdentityrefCodec
 
     @Override
     protected String prefixForNamespace(@Nonnull final URI namespace) {
-        final Module module = context.findModuleByNamespaceAndRevision(namespace, null);
-        return module == null ? null : module.getName();
+        final Iterator<Module> modules = context.findModules(namespace).iterator();
+        return modules.hasNext() ? modules.next().getName() : null;
     }
 }
index 795a40f2f72e1e80beed7102d3f48d91c91dec6c..67eed3ad303712eadb276cf7270ab9fb77988a6b 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.model.api;
 
 import java.util.Date;
+import java.util.Optional;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 
 /**
@@ -34,7 +35,12 @@ public interface ModuleIdentifier {
      *         keyword
      */
     // FIXME: BUG-4688: should return Optional<Revision>
-    // FIXME: this should not be here
-    Date getRevision();
+    Optional<Date> getRevision();
 
+    static int compareRevisions(final Optional<Date> first, final Optional<Date> second) {
+        if (!first.isPresent()) {
+            return second.isPresent() ? -1 : 0;
+        }
+        return second.isPresent() ? first.get().compareTo(second.get()) : 1;
+    }
 }
index 5faaa0628f0754c64923ace974601702e7d30cf1..53e97ab655931112c1108526d24262260247133d 100644 (file)
@@ -12,8 +12,10 @@ import java.net.URI;
 import java.util.Date;
 import java.util.Optional;
 import java.util.Set;
+import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
 
 /**
  * The interface represents static view of compiled yang files,
@@ -65,23 +67,34 @@ public interface SchemaContext extends ContainerSchemaNode {
     Set<ExtensionDefinition> getExtensions();
 
     /**
-     * Returns module instance (from the context) with concrete name and
-     * revision date.
+     * Returns module instance (from the context) with concrete name and revision date.
      *
      * @param name
      *            string with the module name
      * @param revision
-     *            date of the module revision
-     * @return module instance which has name and revision (if specified) the
-     *         same as are the values specified in parameters <code>name</code>
-     *         and <code>revision</code>. In other cases the <code>null</code>
-     *         value is returned.
-     *
+     *            date of the module revision, may be null
+     * @return module instance which has name and revision the same as are the values specified in parameters
+     *         <code>name</code> and <code>revision</code>.
      */
-    Module findModuleByName(String name, Date revision);
+    Optional<Module> findModule(String name, @Nullable Date revision);
+
+    default Optional<Module> findModule(final URI namespace, @Nullable final Date revision) {
+        return findModule(QNameModule.create(namespace, revision));
+    }
 
-    default Optional<Module> findAnyModuleByName(final String name) {
-        return Optional.ofNullable(findModuleByName(name, null));
+    default Optional<Module> findModule(final QNameModule qnameModule) {
+        return getModules().stream().filter(m -> qnameModule.equals(m.getQNameModule())).findAny();
+    }
+
+    /**
+     * Returns module instances (from the context) with a concrete name.
+     *
+     * @param name
+     *            string with the module name
+     * @return set of module instances with specified name.
+     */
+    default Set<Module> findModules(final String name) {
+        return Sets.filter(getModules(), m -> name.equals(m.getName()));
     }
 
     /**
@@ -92,27 +105,7 @@ public interface SchemaContext extends ContainerSchemaNode {
      * @return module instance which has namespace equal to the
      *         <code>namespace</code> or <code>null</code> in other cases
      */
-    default Set<Module> findModuleByNamespace(final URI namespace) {
+    default Set<Module> findModules(final URI namespace) {
         return Sets.filter(getModules(), m -> namespace.equals(m.getNamespace()));
     }
-
-    /**
-     * Returns module instance based on given namespace and revision. If
-     * revision is not specified, returns module with newest revision.
-     *
-     * @param namespace Module namespace, may be null
-     * @param revision Module revision, may be null
-     * @return Matching module or null if a match is not found
-     */
-    default Module findModuleByNamespaceAndRevision(final URI namespace, final Date revision) {
-        if (namespace == null) {
-            return null;
-        }
-        for (Module module : findModuleByNamespace(namespace)) {
-            if (revision == null || revision.equals(module.getRevision())) {
-                return module;
-            }
-        }
-        return null;
-    }
 }
index 028809a10dc6483f727482aa5ba39cef8ae577b4..9df4db341a29672ddbfe0b2c0e8f9b44f32a9088 100644 (file)
@@ -15,7 +15,6 @@ import static org.junit.Assert.assertTrue;
 import java.io.BufferedOutputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.OutputStream;
-import java.util.Date;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.Module;
@@ -34,9 +33,7 @@ public class Bug6856Test {
         final OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
         final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
 
-        final Date revision = QName.parseRevision("2017-02-28");
-
-        final Module fooModule = schemaContext.findModuleByName("foo", revision);
+        final Module fooModule = schemaContext.findModule("foo", QName.parseRevision("2017-02-28")).get();
         YinExportUtils.writeModuleToOutputStream(schemaContext, fooModule, bufferedOutputStream);
 
         final String output = byteArrayOutputStream.toString();
@@ -56,9 +53,7 @@ public class Bug6856Test {
         final OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
         final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
 
-        final Date revision = QName.parseRevision("2017-02-28");
-
-        final Module barModule = schemaContext.findModuleByName("bar", revision);
+        final Module barModule = schemaContext.findModule("bar", QName.parseRevision("2017-02-28")).get();
         YinExportUtils.writeModuleToOutputStream(schemaContext, barModule, bufferedOutputStream);
 
         final String output = byteArrayOutputStream.toString();
index 61d0937800c92f333c31497e0b1d2336d17d6479..33cb1426da847f4deabe138ee79f9dcd0b23922d 100644 (file)
@@ -11,14 +11,13 @@ import java.util.Date;
 import java.util.Optional;
 import org.immutables.value.Value;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 @Value.Immutable
 abstract class AbstractSchemaContext extends CommonContainerSchemaNode implements SchemaContext {
 
     @Override
-    public Module findModuleByName(final String name, final Date revision) {
+    public Optional<Module> findModule(final String name, final Date revision) {
         throw new UnsupportedOperationException("Not implemented");
     }
 }
index 5323edf99ea0c7df065ca1f1b4a3c93acc228ef7..6f3cc009fd4942fffad1cbfbd6c5971409b741a4 100644 (file)
@@ -17,6 +17,8 @@ import java.util.Date;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
 import java.util.Set;
 import java.util.TreeSet;
 import javax.annotation.Nonnull;
@@ -99,19 +101,20 @@ public abstract class AbstractSchemaContext implements SchemaContext {
         return extensions;
     }
 
+
     @Override
-    public Module findModuleByName(final String name, final Date revision) {
+    public Optional<Module> findModule(final String name, final Date revision) {
         for (final Module module : getNameToModules().get(name)) {
-            if (revision == null || revision.equals(module.getRevision())) {
-                return module;
+            if (Objects.equals(revision, module.getRevision())) {
+                return Optional.of(module);
             }
         }
 
-        return null;
+        return Optional.empty();
     }
 
     @Override
-    public Set<Module> findModuleByNamespace(final URI namespace) {
+    public Set<Module> findModules(final URI namespace) {
         final Set<Module> ret = getNamespaceToModules().get(namespace);
         return ret == null ? Collections.emptySet() : ret;
     }
index aab4c20145fc9015ad47fc3ab9c951a0354799ed..01598ab720af162858f614f20d59ab91501afca5 100644 (file)
@@ -34,14 +34,18 @@ public final class ModuleIdentifierImpl implements ModuleIdentifier {
         this.qnameModule = QNameModule.create(namespace.orElse(null), revision.orElse(null));
     }
 
+    public static ModuleIdentifier create(final String name, final Optional<Date> revision) {
+        return new ModuleIdentifierImpl(name, Optional.empty(), revision);
+    }
+
     public static ModuleIdentifier create(final String name, final Optional<URI> namespace,
             final Optional<Date> revision) {
         return new ModuleIdentifierImpl(name, namespace, revision);
     }
 
     @Override
-    public Date getRevision() {
-        return qnameModule.getRevision();
+    public Optional<Date> getRevision() {
+        return Optional.ofNullable(qnameModule.getRevision());
     }
 
     @Override
index 6eb4062712c3d0833f08879834ece069ee3c849e..67ab8ed8ddacaa01042a17f65638393edc79cac0 100644 (file)
@@ -22,7 +22,6 @@ import java.util.regex.Pattern;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -222,20 +221,20 @@ public final class SchemaContextUtil {
         final QName qname = schemaNode.getPath().getLastComponent();
         Preconditions.checkState(qname != null, "Schema Path contains invalid state of path parts. "
                 + "The Schema Path MUST contain at least ONE QName  which defines namespace and Local name of path.");
-        return context.findModuleByNamespaceAndRevision(qname.getNamespace(), qname.getRevision());
+        return context.findModule(qname.getModule()).orElse(null);
     }
 
     public static SchemaNode findNodeInSchemaContext(final SchemaContext context, final Iterable<QName> path) {
         final QName current = path.iterator().next();
 
         LOG.trace("Looking up module {} in context {}", current, path);
-        final Module module = context.findModuleByNamespaceAndRevision(current.getNamespace(), current.getRevision());
-        if (module == null) {
+        final Optional<Module> module = context.findModule(current.getModule());
+        if (!module.isPresent()) {
             LOG.debug("Module {} not found", current);
             return null;
         }
 
-        return findNodeInModule(module, path);
+        return findNodeInModule(module.get(), path);
     }
 
     /**
@@ -597,7 +596,7 @@ public final class SchemaContextUtil {
         final Set<ModuleImport> imports = module.getImports();
         for (final ModuleImport mi : imports) {
             if (prefix.equals(mi.getPrefix())) {
-                return context.findModuleByName(mi.getModuleName(), mi.getRevision());
+                return context.findModule(mi.getModuleName(), mi.getRevision()).orElse(null);
             }
         }
         return null;
@@ -724,10 +723,11 @@ public final class SchemaContextUtil {
             return null;
         }
 
-        final Module parentModule = schemaContext.findModuleByNamespaceAndRevision(qname.getNamespace(),
-                qname.getRevision());
+        final Optional<Module> parentModule = schemaContext.findModule(qname.getModule());
+        Preconditions.checkArgument(parentModule.isPresent(), "Failed to find parent module for %s", qname);
+
         final DataSchemaNode dataSchemaNode = (DataSchemaNode) SchemaContextUtil.findDataSchemaNode(schemaContext,
-            parentModule, strippedPathStatement);
+            parentModule.get(), strippedPathStatement);
         final TypeDefinition<?> targetTypeDefinition = typeDefinition(dataSchemaNode);
         if (targetTypeDefinition instanceof LeafrefTypeDefinition) {
             return getBaseTypeForLeafRef((LeafrefTypeDefinition) targetTypeDefinition, schemaContext, dataSchemaNode);
@@ -747,9 +747,7 @@ public final class SchemaContextUtil {
                 nodeType = nodeType.getBaseType();
             }
 
-            final QNameModule typeDefModuleQname = nodeType.getQName().getModule();
-            return schemaContext.findModuleByNamespaceAndRevision(typeDefModuleQname.getNamespace(),
-                    typeDefModuleQname.getRevision());
+            return schemaContext.findModule(nodeType.getQName().getModule()).orElse(null);
         }
 
         return SchemaContextUtil.findParentModule(schemaContext, schemaNode);
index fe99d93de6d1dbe90ecf3d51ecb7d415c2fc70d0..8cd8bf4d8ca1c6230673fa0e4d34f1a6bd1bcebc 100644 (file)
@@ -545,14 +545,13 @@ public class SchemaContextProxyTest {
         //asserting collections
         if (expected != null) {
             for (final Module module : expected) {
-                assertEquals(module, filteringSchemaContextProxy.findModuleByName(module.getName(),
-                            module.getRevision()));
+                assertEquals(module, filteringSchemaContextProxy.findModule(module.getName(), module.getRevision())
+                    .get());
 
-                Set<Module> mod = filteringSchemaContextProxy.findModuleByNamespace(module.getNamespace());
+                Set<Module> mod = filteringSchemaContextProxy.findModules(module.getNamespace());
                 assertTrue(mod.contains(module));
-
-                assertEquals(module, filteringSchemaContextProxy.findModuleByNamespaceAndRevision(module.getNamespace(),
-                            module.getRevision()));
+                assertEquals(module, filteringSchemaContextProxy.findModule(module.getNamespace(),
+                    module.getRevision()).get());
             }
         }
     }
index d7b751322b3fb62d90a82146b63a93bdd6afe91e..1160d743d1c31b6dc6041378d4d5fd8d115c7d49 100644 (file)
@@ -8,12 +8,16 @@
 package org.opendaylight.yangtools.yang.model.util;
 
 import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
 
 import java.util.Collections;
+import java.util.Optional;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -30,6 +34,7 @@ public class SchemaContextUtilTest {
     @Test
     public void testFindDummyData() {
         MockitoAnnotations.initMocks(this);
+        doReturn(Optional.empty()).when(mockSchemaContext).findModule(any(QNameModule.class));
 
         QName qname = QName.create("TestQName");
         SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qname), true);
index 69bf71821e8cdc3c98d20d799fdbaba22692d882..6fc3c3c034fcadb80a804aae00072b95e4692d23 100644 (file)
@@ -421,7 +421,8 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
         Preconditions.checkState(currentPhase == ModelProcessingPhase.SOURCE_PRE_LINKAGE,
                 "Required library sources can be collected only in ModelProcessingPhase.SOURCE_PRE_LINKAGE phase,"
                         + " but current phase was %s", currentPhase);
-        final TreeBasedTable<String, Date, SourceSpecificContext> libSourcesTable = TreeBasedTable.create();
+        final TreeBasedTable<String, Optional<Date>, SourceSpecificContext> libSourcesTable = TreeBasedTable.create(
+            String::compareTo, ModuleIdentifier::compareRevisions);
         for (final SourceSpecificContext libSource : libSources) {
             final ModuleIdentifier libSourceIdentifier = Preconditions.checkNotNull(libSource.getRootIdentifier());
             libSourcesTable.put(libSourceIdentifier.getName(), libSourceIdentifier.getRevision(), libSource);
@@ -436,7 +437,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
     }
 
     private void collectRequiredSourcesFromLib(
-            final TreeBasedTable<String, Date, SourceSpecificContext> libSourcesTable,
+            final TreeBasedTable<String, Optional<Date>, SourceSpecificContext> libSourcesTable,
             final Set<SourceSpecificContext> requiredLibs, final SourceSpecificContext source) {
         for (final SourceIdentifier requiredSource : source.getRequiredSources()) {
             final SourceSpecificContext libSource = getRequiredLibSource(requiredSource, libSourcesTable);
@@ -447,12 +448,14 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
     }
 
     private static SourceSpecificContext getRequiredLibSource(final SourceIdentifier requiredSource,
-            final TreeBasedTable<String, Date, SourceSpecificContext> libSourcesTable) {
+            final TreeBasedTable<String, Optional<Date>, SourceSpecificContext> libSourcesTable) {
         return requiredSource.getRevision() == null ? getLatestRevision(libSourcesTable.row(requiredSource.getName()))
-                : libSourcesTable.get(requiredSource.getName(), QName.parseRevision(requiredSource.getRevision()));
+                : libSourcesTable.get(requiredSource.getName(),
+                    Optional.of(QName.parseRevision(requiredSource.getRevision())));
     }
 
-    private static SourceSpecificContext getLatestRevision(final SortedMap<Date, SourceSpecificContext> sourceMap) {
+    private static SourceSpecificContext getLatestRevision(final SortedMap<Optional<Date>,
+            SourceSpecificContext> sourceMap) {
         return sourceMap != null && !sourceMap.isEmpty() ? sourceMap.get(sourceMap.lastKey()) : null;
     }
 
index 38157523d3936eeb0aafaf118c04d2309d5c3865..6d248e212e1db8e9271a2266410aaad04f5cc0f5 100644 (file)
@@ -156,7 +156,7 @@ public class ImportStatementDefinition extends
                     NamespaceKeyCriterion.latestRevisionModule(moduleName), SOURCE_LINKAGE);
             } else {
                 imported = importAction.requiresCtx(stmt, ModuleNamespace.class,
-                    ModuleIdentifierImpl.create(moduleName, Optional.empty(), Optional.of(revision)), SOURCE_LINKAGE);
+                    ModuleIdentifierImpl.create(moduleName, Optional.of(revision)), SOURCE_LINKAGE);
             }
 
             final Prerequisite<Mutable<?, ?, ?>> linkageTarget = importAction.mutatesCtx(stmt.getRoot(),
@@ -327,8 +327,9 @@ public class ImportStatementDefinition extends
 
         private static SemVerSourceIdentifier createSemVerModuleIdentifier(
                 final ModuleIdentifier importedModuleIdentifier, final SemVer semVer) {
-            final String formattedRevision = SimpleDateFormatUtil.getRevisionFormat().format(
-                    importedModuleIdentifier.getRevision());
+            final String formattedRevision = importedModuleIdentifier.getRevision().map(
+                date -> SimpleDateFormatUtil.getRevisionFormat().format(date))
+                    .orElse(null);
             return SemVerSourceIdentifier.create(importedModuleIdentifier.getName(), formattedRevision, semVer);
         }
     }
index fc6777dfa1dadd3738a50ac8d0af56de1a0c0544..9dd38ee88c6af851e2692bd4d3f75a5a9fb4fcc3 100644 (file)
@@ -91,8 +91,8 @@ public class IncludeStatementImpl extends AbstractDeclaredStatement<String> impl
                     NamespaceKeyCriterion.latestRevisionModule(submoduleName), SOURCE_LINKAGE);
             } else {
                 requiresCtxPrerequisite = includeAction.requiresCtx(stmt, SubmoduleNamespace.class,
-                    ModuleIdentifierImpl.create(submoduleName, Optional.empty(),
-                        Optional.of(revision.getStatementArgument())), SOURCE_LINKAGE);
+                    ModuleIdentifierImpl.create(submoduleName, Optional.of(revision.getStatementArgument())),
+                    SOURCE_LINKAGE);
             }
 
             includeAction.apply(new InferenceAction() {
index 74d0c02363ecb1454f0a2069809ff820f0bc5d88..c650e6d729b8a608c52f58f491303b63ca6bd028 100644 (file)
@@ -124,8 +124,7 @@ public class ModuleStatementSupport extends
         final QNameModule qNameModule = QNameModule.create(moduleNs, revisionDate.orElse(null)).intern();
 
         stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
-        stmt.setRootIdentifier(ModuleIdentifierImpl.create(stmt.getStatementArgument(),
-                Optional.empty(), revisionDate));
+        stmt.setRootIdentifier(ModuleIdentifierImpl.create(stmt.getStatementArgument(), revisionDate));
     }
 
     @Override
@@ -152,7 +151,7 @@ public class ModuleStatementSupport extends
         }
 
         final ModuleIdentifier moduleIdentifier = ModuleIdentifierImpl.create(stmt.getStatementArgument(),
-                Optional.empty(), revisionDate);
+                revisionDate);
 
         stmt.addContext(ModuleNamespace.class, moduleIdentifier, stmt);
         stmt.addContext(ModuleNamespaceForBelongsTo.class, moduleIdentifier.getName(), stmt);
index b57125fc936852f5093ccbb3214322ac108bda75..4ea6a4d35da58f7417e1cd71cf0df39637a74b58 100644 (file)
@@ -128,7 +128,7 @@ public class SubmoduleStatementImpl extends AbstractRootStatement<SubmoduleState
             final Optional<Date> revisionDate = maybeDate != null ? Optional.of(maybeDate) : DEFAULT_REVISION;
 
             final ModuleIdentifier submoduleIdentifier = ModuleIdentifierImpl.create(stmt.getStatementArgument(),
-                    Optional.empty(), revisionDate);
+                    revisionDate);
             return submoduleIdentifier;
         }
 
index 6fb79e921e0dee962869c24469ded80ef0250b04..0312047ff8f1abe3558a0bb52a77f1c599073fef 100644 (file)
@@ -51,7 +51,7 @@ public class SharedSchemaRepositoryWithFeaturesTest {
         assertTrue(testSchemaContextFuture.isDone());
         assertSchemaContext(testSchemaContextFuture.get(), 1);
 
-        final Module module = testSchemaContextFuture.get().findModuleByName("foobar", null);
+        final Module module = testSchemaContextFuture.get().findModules("foobar").iterator().next();
         assertNotNull(module);
         assertEquals(2, module.getChildNodes().size());
 
@@ -92,7 +92,7 @@ public class SharedSchemaRepositoryWithFeaturesTest {
         assertTrue(testSchemaContextFuture.isDone());
         assertSchemaContext(testSchemaContextFuture.get(), 1);
 
-        final Module module = testSchemaContextFuture.get().findModuleByName("foobar", null);
+        final Module module = testSchemaContextFuture.get().findModules("foobar").iterator().next();
         assertNotNull(module);
         assertEquals(3, module.getChildNodes().size());
 
@@ -138,7 +138,7 @@ public class SharedSchemaRepositoryWithFeaturesTest {
         assertTrue(testSchemaContextFuture.isDone());
         assertSchemaContext(testSchemaContextFuture.get(), 1);
 
-        final Module module = testSchemaContextFuture.get().findModuleByName("foobar", null);
+        final Module module = testSchemaContextFuture.get().findModules("foobar").iterator().next();
         assertNotNull(module);
         assertEquals(1, module.getChildNodes().size());
 
index aa0f39bfb0f17d894846c9b798b736fc9797c505..6b60dd7c5e5db51999772ec8b0257fc7950689b4 100644 (file)
@@ -44,9 +44,7 @@ public class ConstraintDefinitionsTest {
         final SchemaContext schemaContext = reactor.buildEffective();
         assertNotNull(schemaContext);
 
-        final Module testModule = schemaContext.findModuleByName("foo", QName.parseRevision("2016-09-20"));
-        assertNotNull(testModule);
-
+        final Module testModule = schemaContext.findModule("foo", QName.parseRevision("2016-09-20")).get();
         final LeafSchemaNode mandatoryLeaf1 = (LeafSchemaNode) testModule.getDataChildByName(
                 QName.create(testModule.getQNameModule(), "mandatory-leaf-1"));
         assertNotNull(mandatoryLeaf1);
index 14137f8ad53abf7aa703aadadd9432cc7341c3c4..eb1158f2814bc90dbd38e5b03c7b52e27549d070 100644 (file)
@@ -13,7 +13,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.util.Date;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -33,10 +32,7 @@ public class Bug6871Test {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6871/foo.yang");
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2016-12-14");
-
-        final Module foo = schemaContext.findModuleByName("foo", revision);
-        assertNotNull(foo);
+        final Module foo = schemaContext.findModule("foo", QName.parseRevision("2016-12-14")).get();
 
         final Set<NotificationDefinition> notifications = foo.getNotifications();
         assertEquals(1, notifications.size());
index 19f2312e634a3df8ee944a5aab4615b93f43bccf..22a75352775ce299f0bbf9eb4fa82f33e59465fa 100644 (file)
@@ -47,7 +47,7 @@ public class Bug6874Test {
         assertNotNull(schemaContext);
 
         // Test for valid include statement
-        final Module testModule = schemaContext.findModuleByName("root-module", null);
+        final Module testModule = schemaContext.findModules("root-module").iterator().next();
         assertNotNull(testModule);
 
         // Test for valid import statement
index 0c8e31b1fc9aa6d786f57a2cfcea4925e2a07e8c..e45b6ca2ce014305f25f15d7d38c738bb0a8bf27 100644 (file)
@@ -15,7 +15,6 @@ import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
-import java.util.Date;
 import java.util.List;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -43,11 +42,7 @@ public class Bug6887Test {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo.yang");
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2017-01-26");
-
-        final Module foo = schemaContext.findModuleByName("foo", revision);
-        assertNotNull(foo);
-
+        final Module foo = schemaContext.findModule("foo", QName.parseRevision("2017-01-26")).get();
         final LeafSchemaNode myEnumerationLeaf = (LeafSchemaNode) foo.getDataChildByName(
                 QName.create(foo.getQNameModule(), "my-enumeration-leaf"));
         assertNotNull(myEnumerationLeaf);
@@ -173,11 +168,7 @@ public class Bug6887Test {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar.yang");
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2017-02-02");
-
-        final Module bar = schemaContext.findModuleByName("bar", revision);
-        assertNotNull(bar);
-
+        final Module bar = schemaContext.findModule("bar", QName.parseRevision("2017-02-02")).get();
         final LeafSchemaNode myBitsLeaf = (LeafSchemaNode) bar.getDataChildByName(
                 QName.create(bar.getQNameModule(), "my-bits-leaf"));
         assertNotNull(myBitsLeaf);
index 70b2c398d4b01f37e1903ad5c03a4877b71e2077..df2e0a80f4cea86bcdd8f83e36d14e12a0995c3e 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.util.Date;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
@@ -29,10 +28,7 @@ public class Bug9241Test {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug9241/foo.yang");
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2017-10-13");
-
-        final Module fooModule = schemaContext.findModuleByName("foo", revision);
-        assertNotNull(fooModule);
+        final Module fooModule = schemaContext.findModule("foo", QName.parseRevision("2017-10-13")).get();
 
         final ContainerSchemaNode actionCont = (ContainerSchemaNode) fooModule.getDataChildByName(QName.create(
                 fooModule.getQNameModule(), "action-cont"));
index 64cc06c4bf729c8aac47caa7dc8c25507b4aaccf..bce4e8df1f8a9468315232c2fdcd4acd5fcb6fdb 100644 (file)
@@ -29,9 +29,7 @@ public class IdentityStatementTest {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/identity-stmt/foo.yang");
         assertNotNull(schemaContext);
 
-        final Module foo = schemaContext.findModuleByName("foo", QName.parseRevision("2016-12-21"));
-        assertNotNull(foo);
-
+        final Module foo = schemaContext.findModule("foo", QName.parseRevision("2016-12-21")).get();
         final Set<IdentitySchemaNode> identities = foo.getIdentities();
         for (final IdentitySchemaNode identity : identities) {
             if ("derived-id".equals(identity.getQName().getLocalName())) {
index 3ac2bcadc25bfeb5d46eeeb147de9a14ffc469b0..8715356092eaf088b1589fb151f1df8a3c5911b5 100644 (file)
@@ -13,7 +13,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.util.Date;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -32,11 +31,7 @@ public class IdentityrefStatementTest {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/identityref-stmt/foo.yang");
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2017-01-11");
-
-        final Module foo = schemaContext.findModuleByName("foo", revision);
-        assertNotNull(foo);
-
+        final Module foo = schemaContext.findModule("foo", QName.parseRevision("2017-01-11")).get();
         final Set<IdentitySchemaNode> identities = foo.getIdentities();
         assertEquals(3, identities.size());
 
index f83fa110b26ecd561a48c54439a79e4b0b644a88..2fe30aa7a17e2b5e8a25a3ebd4304e1da3dec513 100644 (file)
@@ -13,11 +13,9 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.util.Date;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -33,11 +31,7 @@ public class LeafrefStatementTest {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/leafref-stmt/foo.yang");
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2016-12-20");
-
-        final Module foo = schemaContext.findModuleByName("foo", revision);
-        assertNotNull(foo);
-
+        final Module foo = schemaContext.findModule("foo", QName.parseRevision("2016-12-20")).get();
         final Set<TypeDefinition<?>> typeDefinitions = foo.getTypeDefinitions();
         assertEquals(1, typeDefinitions.size());
 
index 0c098d96aa988fc00ae77614be481458422884af..3425c68280cac68bdfcb35a23b9f2cfc18a3ed8a 100644 (file)
@@ -10,17 +10,21 @@ package org.opendaylight.yangtools.yang.parser.util;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
 
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.text.ParseException;
 import java.util.Collections;
+import java.util.Optional;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
@@ -50,6 +54,7 @@ public class SchemaContextUtilTest {
     @Test
     public void testFindDummyData() {
         MockitoAnnotations.initMocks(this);
+        doReturn(Optional.empty()).when(mockSchemaContext).findModule(any(QNameModule.class));
 
         final QName qName = QName.create("TestQName");
         final SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
@@ -78,8 +83,7 @@ public class SchemaContextUtilTest {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
 
-        final Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
-                QName.parseRevision("2014-10-07"));
+        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
 
         SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName(QName.create(
                 myModule.getQNameModule(), "my-container"))).getDataChildByName(QName.create(myModule.getQNameModule(),
@@ -197,8 +201,7 @@ public class SchemaContextUtilTest {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
 
-        final Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
-                QName.parseRevision("2014-10-07"));
+        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
 
         SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName(QName.create(
                 myModule.getQNameModule(), "my-container"))).getDataChildByName(QName.create(myModule.getQNameModule(),
@@ -296,8 +299,7 @@ public class SchemaContextUtilTest {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
 
-        final Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
-                QName.parseRevision("2014-10-07"));
+        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
 
         SchemaNode testNode = myModule.getDataChildByName(QName.create(myModule.getQNameModule(), "my-container"));
 
@@ -363,8 +365,7 @@ public class SchemaContextUtilTest {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
 
-        final Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
-                QName.parseRevision("2014-10-07"));
+        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
 
         final DataSchemaNode node = myModule
                 .getDataChildByName(QName.create(myModule.getQNameModule(), "my-container"));
@@ -419,13 +420,10 @@ public class SchemaContextUtilTest {
     @Test
     public void findDataSchemaNodeTest() throws URISyntaxException, IOException, YangSyntaxErrorException,
             ReactorException {
-
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
-
-        final Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
-                QName.parseRevision("2014-10-07"));
-        final Module importedModule = context.findModuleByNamespaceAndRevision(new URI("uri:imported-module"),
-                QName.parseRevision("2014-10-07"));
+        final Module module = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+        final Module importedModule = context.findModule(new URI("uri:imported-module"),
+            QName.parseRevision("2014-10-07")).get();
 
         final SchemaNode testNode = ((ContainerSchemaNode) importedModule.getDataChildByName(QName.create(
                 importedModule.getQNameModule(), "my-imported-container"))).getDataChildByName(QName.create(
@@ -448,9 +446,7 @@ public class SchemaContextUtilTest {
         // final RevisionAwareXPath nonCondXPath) {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
-
-        final Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
-                QName.parseRevision("2014-10-07"));
+        final Module module = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
 
         final GroupingDefinition grouping = getGroupingByName(module, "my-grouping");
         final SchemaNode testNode = grouping.getDataChildByName(QName.create(module.getQNameModule(),
@@ -536,9 +532,7 @@ public class SchemaContextUtilTest {
             YangSyntaxErrorException, ParseException, ReactorException {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
-
-        final Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
-                QName.parseRevision("2014-10-07"));
+        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
 
         // find grouping in container
         DataNodeContainer dataContainer = (DataNodeContainer) myModule.getDataChildByName(QName.create(
@@ -738,8 +732,7 @@ public class SchemaContextUtilTest {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
 
-        final Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
-                QName.parseRevision("2014-10-07"));
+        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
 
         // find grouping in container
         DataNodeContainer dataContainer = (DataNodeContainer) myModule.getDataChildByName(QName.create(
@@ -878,9 +871,7 @@ public class SchemaContextUtilTest {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
 
-        final Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
-                QName.parseRevision("2014-10-07"));
-
+        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
         final ChoiceSchemaNode choice = (ChoiceSchemaNode) getRpcByName(myModule, "my-name").getInput()
                 .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice"));
         final SchemaNode testNode = choice.getCaseNodeByName("case-two").getDataChildByName(
@@ -894,7 +885,5 @@ public class SchemaContextUtilTest {
         assertNotNull(testNode);
         assertNotNull(foundNode);
         assertEquals(testNode, foundNode);
-
     }
-
 }
\ No newline at end of file
index 1dda64c311af96e409f8234c3e3895e22520ff3e..47d19c99742f072098d46ce268a8f80f7bb2f352 100644 (file)
@@ -138,55 +138,41 @@ public class AugmentProcessTest {
         final SchemaContext root = reactor.buildEffective();
         assertNotNull(root);
 
-        final Module augmentedModule = root.findModuleByName("augmented", null);
+        final Module augmentedModule = root.findModules("augmented").iterator().next();
         assertNotNull(augmentedModule);
 
-        final ContainerSchemaNode augParent1Node = (ContainerSchemaNode) root
-                .getDataChildByName(augParent1);
-        final ContainerSchemaNode augParent2Node = (ContainerSchemaNode) augParent1Node
-                .getDataChildByName(augParent2);
-        final ContainerSchemaNode targetContNode = (ContainerSchemaNode) augParent2Node
-                .getDataChildByName(contTarget);
+        final ContainerSchemaNode augParent1Node = (ContainerSchemaNode) root.getDataChildByName(augParent1);
+        final ContainerSchemaNode augParent2Node = (ContainerSchemaNode) augParent1Node.getDataChildByName(augParent2);
+        final ContainerSchemaNode targetContNode = (ContainerSchemaNode) augParent2Node.getDataChildByName(contTarget);
         assertNotNull(targetContNode);
 
         assertNotNull(targetContNode.getChildNodes());
         assertEquals(3, targetContNode.getChildNodes().size());
 
-        final ContainerSchemaNode contAdded1Node = (ContainerSchemaNode) targetContNode
-                .getDataChildByName(contAdded1);
+        final ContainerSchemaNode contAdded1Node = (ContainerSchemaNode) targetContNode.getDataChildByName(contAdded1);
         assertNotNull(contAdded1Node);
-        final ListSchemaNode list1Node = (ListSchemaNode) contAdded1Node
-                .getDataChildByName(list1);
+        final ListSchemaNode list1Node = (ListSchemaNode) contAdded1Node.getDataChildByName(list1);
         assertNotNull(list1Node);
 
-        final ContainerSchemaNode contAdded2Node = (ContainerSchemaNode) targetContNode
-                .getDataChildByName(contAdded2);
+        final ContainerSchemaNode contAdded2Node = (ContainerSchemaNode) targetContNode.getDataChildByName(contAdded2);
         assertNotNull(contAdded2Node);
-        final AnyXmlSchemaNode axmlNode = (AnyXmlSchemaNode) contAdded2Node
-                .getDataChildByName(axml);
+        final AnyXmlSchemaNode axmlNode = (AnyXmlSchemaNode) contAdded2Node.getDataChildByName(axml);
         assertNotNull(axmlNode);
 
-        final ContainerSchemaNode contGrpNode = (ContainerSchemaNode) targetContNode
-                .getDataChildByName(contGrp);
+        final ContainerSchemaNode contGrpNode = (ContainerSchemaNode) targetContNode.getDataChildByName(contGrp);
         assertNotNull(contGrpNode);
-        final AnyXmlSchemaNode axmlGrpNode = (AnyXmlSchemaNode) contGrpNode
-                .getDataChildByName(axmlGrp);
+        final AnyXmlSchemaNode axmlGrpNode = (AnyXmlSchemaNode) contGrpNode.getDataChildByName(axmlGrp);
         assertNotNull(axmlGrpNode);
 
-        final ContainerSchemaNode augCont1Node = (ContainerSchemaNode) root
-                .getDataChildByName(augCont1);
-        final ContainerSchemaNode augCont2Node = (ContainerSchemaNode) augCont1Node
-                .getDataChildByName(augCont2);
+        final ContainerSchemaNode augCont1Node = (ContainerSchemaNode) root.getDataChildByName(augCont1);
+        final ContainerSchemaNode augCont2Node = (ContainerSchemaNode) augCont1Node.getDataChildByName(augCont2);
         assertNotNull(augCont2Node);
 
-        final ContainerSchemaNode grpCont2Node = (ContainerSchemaNode) augCont2Node
-                .getDataChildByName(grpCont2);
-        final ContainerSchemaNode grpCont22Node = (ContainerSchemaNode) grpCont2Node
-                .getDataChildByName(grpCont22);
+        final ContainerSchemaNode grpCont2Node = (ContainerSchemaNode) augCont2Node.getDataChildByName(grpCont2);
+        final ContainerSchemaNode grpCont22Node = (ContainerSchemaNode) grpCont2Node.getDataChildByName(grpCont22);
         assertNotNull(grpCont22Node);
 
-        final ContainerSchemaNode grpAddNode = (ContainerSchemaNode) grpCont22Node
-                .getDataChildByName(grpAdd);
+        final ContainerSchemaNode grpAddNode = (ContainerSchemaNode) grpCont22Node.getDataChildByName(grpAdd);
         assertNotNull(grpAddNode);
     }
 
index 7ca47737fc30d4cf15d9646225b0bafac11bc0b6..0fb1cdddcef201c9e884d727df498403c4e7a04e 100644 (file)
@@ -26,7 +26,7 @@ public class Bug4456Test {
         SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug4456");
         assertNotNull(schema);
 
-        Set<Module> modules = schema.findModuleByNamespace(new URI("foo"));
+        Set<Module> modules = schema.findModules(URI.create("foo"));
         assertEquals(1, modules.size());
         Module moduleFoo = modules.iterator().next();
 
index 8b9e3ce08b1dc4a5c98c50ef808dab84086827bd..1c6452f960168e0ac24b69bde8549d3acba90fbb 100644 (file)
@@ -8,13 +8,17 @@
 
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil.DEFAULT_DATE_REV;
+
 import com.google.common.collect.Range;
 import java.io.File;
+import java.net.URI;
 import java.util.List;
 import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
@@ -33,8 +37,8 @@ public class Bug4623Test {
         // when
         final SchemaContext schemaContext = TestUtils.parseYangSources(extdef, stringWithExt);
 
-        final LeafSchemaNode leaf = (LeafSchemaNode) schemaContext.findModuleByName("types", null).getDataChildByName(
-                QName.create("urn:custom.types.demo", "1970-01-01", "leaf-length-pattern-unknown"));
+        final LeafSchemaNode leaf = (LeafSchemaNode) typesModule(schemaContext).getDataChildByName(
+            QName.create(URI.create("urn:custom.types.demo"), DEFAULT_DATE_REV, "leaf-length-pattern-unknown"));
 
         // then
         Assert.assertNotNull(leaf);
@@ -47,7 +51,8 @@ public class Bug4623Test {
 
         final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.get(0);
         Assert.assertEquals(unknownSchemaNode.getNodeParameter(), "unknown");
-        Assert.assertEquals(unknownSchemaNode.getNodeType().getModule().getNamespace().toString(), "urn:simple.extension.typedefs");
+        Assert.assertEquals(unknownSchemaNode.getNodeType().getModule().getNamespace().toString(),
+            "urn:simple.extension.typedefs");
 
         final LengthConstraint lengthConstraint = ((StringTypeDefinition) type).getLengthConstraint().get();
         final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
@@ -74,8 +79,8 @@ public class Bug4623Test {
         // when
         final SchemaContext schemaContext = TestUtils.parseYangSources(extdef, stringWithExt);
 
-        final LeafSchemaNode leaf = (LeafSchemaNode) schemaContext.findModuleByName("types", null).getDataChildByName(
-                QName.create("urn:custom.types.demo", "1970-01-01", "leaf-length-unknown-pattern"));
+        final LeafSchemaNode leaf = (LeafSchemaNode) typesModule(schemaContext).getDataChildByName(
+                QName.create(URI.create("urn:custom.types.demo"), DEFAULT_DATE_REV, "leaf-length-unknown-pattern"));
 
         // then
         Assert.assertNotNull(leaf);
@@ -88,7 +93,8 @@ public class Bug4623Test {
 
         final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.get(0);
         Assert.assertEquals(unknownSchemaNode.getNodeParameter(), "unknown");
-        Assert.assertEquals(unknownSchemaNode.getNodeType().getModule().getNamespace().toString(), "urn:simple.extension.typedefs");
+        Assert.assertEquals(unknownSchemaNode.getNodeType().getModule().getNamespace().toString(),
+            "urn:simple.extension.typedefs");
 
         final LengthConstraint lengthConstraints = ((StringTypeDefinition) type).getLengthConstraint().get();
         final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
@@ -115,8 +121,8 @@ public class Bug4623Test {
         // when
         final SchemaContext schemaContext = TestUtils.parseYangSources(extdef, stringWithExt);
 
-        final LeafSchemaNode leaf = (LeafSchemaNode) schemaContext.findModuleByName("types", null).getDataChildByName(
-                QName.create("urn:custom.types.demo", "1970-01-01", "leaf-unknown-length-pattern"));
+        final LeafSchemaNode leaf = (LeafSchemaNode) typesModule(schemaContext).getDataChildByName(
+                QName.create(URI.create("urn:custom.types.demo"), DEFAULT_DATE_REV, "leaf-unknown-length-pattern"));
 
         // then
         Assert.assertNotNull(leaf);
@@ -129,7 +135,8 @@ public class Bug4623Test {
 
         final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.get(0);
         Assert.assertEquals(unknownSchemaNode.getNodeParameter(), "unknown");
-        Assert.assertEquals(unknownSchemaNode.getNodeType().getModule().getNamespace().toString(), "urn:simple.extension.typedefs");
+        Assert.assertEquals(unknownSchemaNode.getNodeType().getModule().getNamespace().toString(),
+            "urn:simple.extension.typedefs");
 
         final LengthConstraint lengthConstraints =
                 ((StringTypeDefinition) type).getLengthConstraint().get();
@@ -147,4 +154,8 @@ public class Bug4623Test {
         final PatternConstraint patternConstraint = patternConstraints.get(0);
         Assert.assertEquals(patternConstraint.getRegularExpression(), "^[0-9a-fA-F]$");
     }
+
+    private static Module typesModule(final SchemaContext context) {
+        return context.findModules("types").iterator().next();
+    }
 }
\ No newline at end of file
index e22cc13aebe4d5a29ffb36d2964b233b19b19f15..8d8482302d2d2b0829f0f36d859397aa56b41b23 100644 (file)
@@ -27,8 +27,7 @@ public class Bug4933Test {
         SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug4933/correct");
         assertNotNull(context);
 
-        final Module foo = context.findModuleByName("foo", null);
-
+        final Module foo = context.findModules("foo").iterator().next();
         Set<Deviation> deviations = foo.getDeviations();
         assertEquals(4, deviations.size());
     }
index 9df7aa9dc6812b64ade71d8540017ea10d0627c4..84578c794ab5a3e83e23a9c3c12a4bb886935a8a 100644 (file)
@@ -24,9 +24,8 @@ public class Bug5712Test {
         SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug5712");
         assertNotNull(schemaContext);
 
-        Module badModule = schemaContext.findModuleByName("bad", null);
+        Module badModule = schemaContext.findModules("bad").iterator().next();
         assertNotNull(badModule);
-
         checkThing2TypeDef(badModule);
     }
 
index 66725085e07cf3dca9c3d4f643302b7c7b53a919..7e352554eb269eeac61e7dd392b1533185311c1d 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang.stmt;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Date;
 import java.util.Iterator;
 import java.util.Set;
 import org.junit.Test;
@@ -35,8 +34,7 @@ public class Bug5884Test {
         final QName root = QName.create(NS, REV, "main-container");
         final QName choice = QName.create(NS, REV, "test-choice");
         final QName testContainerQname = QName.create(NS, REV, "test");
-        final Date date = QName.parseRevision("2016-01-01");
-        final Module foo = context.findModuleByName("foo", date);
+        final Module foo = context.findModule("foo", QName.parseRevision("2016-01-01")).get();
         final ContainerSchemaNode rootContainer = (ContainerSchemaNode) context.getDataChildByName(root);
         final ContainerSchemaNode testContainer = (ContainerSchemaNode) rootContainer.getDataChildByName(
             testContainerQname);
index 12e75c81aa18ff4923c118b84574ba5c224f2ef3..665dfa8da844d049961ac8680366ed60d902b0d7 100644 (file)
@@ -41,8 +41,7 @@ public class Bug6491Test {
             throws Exception {
         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6491/".concat(path));
         assertNotNull(context);
-        final Module module = context.findModuleByName("bar", moduleRevision);
-        assertNotNull(module);
+        final Module module = context.findModule("bar", moduleRevision).get();
         final Set<ModuleImport> imports = module.getImports();
         assertNotNull(imports);
         assertEquals(1, imports.size());
index 67822ae3b403e47afa464ba353d183472debe73d..76858e399a907494893944350575aab74a039b19 100644 (file)
@@ -34,13 +34,9 @@ public class Bug6972Test {
         assertEquals(3, schemaContext.getModules().size());
 
         final Date revision = QName.parseRevision("2016-10-20");
-
-        final Module foo = schemaContext.findModuleByName("foo", revision);
-        assertNotNull(foo);
-        final Module bar = schemaContext.findModuleByName("bar", revision);
-        assertNotNull(bar);
-        final Module baz = schemaContext.findModuleByName("baz", revision);
-        assertNotNull(baz);
+        final Module foo = schemaContext.findModule("foo", revision).get();
+        final Module bar = schemaContext.findModule("bar", revision).get();
+        final Module baz = schemaContext.findModule("baz", revision).get();
 
         final QName barExportCont = QName.create("bar-ns", "bar-export", revision);
         final QName barFooCont = QName.create("bar-ns", "bar-foo", revision);
index 34221ace427b76def7628243fafaa36751de3501..70fc2d67e9a1d7650219892584c78a1301943b83 100644 (file)
@@ -31,11 +31,8 @@ public class Bug7440Test {
         assertNotNull(schemaContext);
 
         final Date revision = QName.parseRevision("2016-12-23");
-
-        final Module foo = schemaContext.findModuleByName("foo", revision);
-        assertNotNull(foo);
-        final Module bar = schemaContext.findModuleByName("bar", revision);
-        assertNotNull(bar);
+        final Module foo = schemaContext.findModule("foo", revision).get();
+        final Module bar = schemaContext.findModule("bar", revision).get();
 
         final Set<Deviation> deviations = foo.getDeviations();
         assertEquals(1, deviations.size());
index 3dc60feef380a5651367668e1683e8ec0c5be41e..c79a918a67e30e4bdfb85a73dd19ef3638f7a05a 100644 (file)
@@ -31,20 +31,18 @@ public class Bug7480Test {
         final Set<Module> modules = context.getModules();
         assertEquals(8, modules.size());
 
-        assertNotNull(context.findModuleByNamespaceAndRevision(new URI("foo-imp"), QName.parseRevision("2017-01-23")));
-        assertEquals(1, context.findModuleByNamespace(new URI("foo-imp-2")).size());
-        assertEquals(1, context.findModuleByNamespace(new URI("foo-imp-imp")).size());
-        assertEquals(1, context.findModuleByNamespace(new URI("bar")).size());
-        assertEquals(1, context.findModuleByNamespace(new URI("baz")).size());
-        assertNotNull(context.findModuleByNamespaceAndRevision(new URI("baz-imp"), QName.parseRevision("2002-01-01")));
-        final Set<Module> foo = context.findModuleByNamespace(new URI("foo"));
+        assertNotNull(context.findModule(new URI("foo-imp"), QName.parseRevision("2017-01-23")));
+        assertEquals(1, context.findModules(new URI("foo-imp-2")).size());
+        assertEquals(1, context.findModules(new URI("foo-imp-imp")).size());
+        assertEquals(1, context.findModules(new URI("bar")).size());
+        assertEquals(1, context.findModules(new URI("baz")).size());
+        assertTrue(context.findModule(new URI("baz-imp"), QName.parseRevision("2002-01-01")).isPresent());
+        final Set<Module> foo = context.findModules(new URI("foo"));
         assertEquals(1, foo.size());
         final Set<Module> subFoos = foo.iterator().next().getSubmodules();
         assertEquals(1, subFoos.size());
 
-        final Module parentMod = context.findModuleByNamespaceAndRevision(new URI("parent-mod-ns"),
-            QName.parseRevision("2017-09-07"));
-        assertNotNull(parentMod);
+        final Module parentMod = context.findModule(new URI("parent-mod-ns"), QName.parseRevision("2017-09-07")).get();
         assertEquals(1, parentMod.getSubmodules().size());
     }
 
index b89f5f20a9166602a763b8adb32dcbe469c5c5bf..9f512b41ee56dd693298a5d9a31b098e7b6c1ade 100644 (file)
@@ -14,6 +14,7 @@ import static org.junit.Assert.fail;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -24,9 +25,7 @@ public class Bug8597Test {
         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug8597");
         assertNotNull(context);
 
-        final Module foo = context.findModuleByName("foo", QName.parseRevision("1970-01-01"));
-        assertNotNull(foo);
-
+        final Module foo = context.findModule("foo", SimpleDateFormatUtil.DEFAULT_DATE_REV).get();
         final Set<ModuleImport> imports = foo.getImports();
 
         for (final ModuleImport moduleImport : imports) {
index 852c4bf4e535e6e5f913241c570e37859e693916..15b3f3e5ca809f95f04bb154325c2b82ef2294d4 100644 (file)
@@ -23,7 +23,7 @@ public class Bug9005Test {
         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug9005");
         assertNotNull(context);
 
-        final Module foo = context.findModuleByName("foo", QName.parseRevision("2017-07-07"));
+        final Module foo = context.findModule("foo", QName.parseRevision("2017-07-07")).get();
 
         final Set<ModuleImport> imports = foo.getImports();
         assertEquals(1, imports.size());
index 94cc63d7c694609ef2aef3b0735280bcd57f0241..ec7158245a1acb6b8142e9ec2653d98183acf2d4 100644 (file)
@@ -29,9 +29,8 @@ public class Bug9242Test {
 
         final Date revision = QName.parseRevision("2017-10-13");
 
-        final Module rootModule = schemaContext.findModuleByName("root-module", revision);
-        final Module impModule = schemaContext.findModuleByName("imp-module", revision);
-        assertNotNull(impModule);
+        final Module rootModule = schemaContext.findModule("root-module", revision).get();
+        final Module impModule = schemaContext.findModule("imp-module", revision).get();
 
         TypeDefinition<?> deviatedMyLeafType = null;
         TypeDefinition<?> deviatedMyLeaf2Type = null;
index eee11c1094349fa7f324925e1335ebed8e73bc3f..5dedf724d61368122aadd5263e6d6165b7bff18d 100644 (file)
@@ -13,7 +13,6 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Date;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -29,11 +28,7 @@ public class Bug9244Test {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug9244/");
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2017-10-13");
-
-        final Module barModule = schemaContext.findModuleByName("bar", revision);
-        assertNotNull(barModule);
-
+        final Module barModule = schemaContext.findModule("bar", QName.parseRevision("2017-10-13")).get();
         final ContainerSchemaNode barCont = (ContainerSchemaNode) barModule.getDataChildByName(
                 QName.create(barModule.getQNameModule(), "bar-cont"));
         assertNotNull(barCont);
index 23ad0d971024b289335e067d7c666bde87bfa2f8..cd47bf687f929c26f08f74d5165cada4a4653bfa 100644 (file)
@@ -46,8 +46,8 @@ public class CaseStmtTest {
         String date_s = "2015-09-09 00:00:00.0";
         SimpleDateFormat dt = SimpleDateFormatUtil.getRevisionFormat();
         Date date = dt.parse(date_s);
-        rootFoo = schema.findModuleByName("foo", date);
-        rootBar = schema.findModuleByName("bar", date);
+        rootFoo = schema.findModule("foo", date).get();
+        rootBar = schema.findModule("bar", date).get();
         assertNotNull(rootFoo);
         assertNotNull(rootBar);
         qnameFoo = QNameModule.create(URI.create("foo"), date);
index 82c5d651e20187df454d1363fcd95ef8aa781c39..b2ab02b7cc2db4a7d344a73e5fea1b89e29fc020 100644 (file)
@@ -39,7 +39,7 @@ public class ChoiceStmtTest {
         final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("foo", null);
+        final Module testModule = result.findModules("foo").iterator().next();
         assertNotNull(testModule);
 
         final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
index 393a95befb6d6bbcf06a02698303f3d35b9a2857..6119f70e594e2d0e4f80c1718a85f611e82be28f 100644 (file)
@@ -44,9 +44,8 @@ public class ControllerStmtParserTest {
 
     private static void salDomBrokerImplModuleTest(final SchemaContext context)
             throws ParseException {
-        final Module module = context.findModuleByName("opendaylight-sal-dom-broker-impl",
-            QName.parseRevision("2013-10-28"));
-        assertNotNull(module);
+        final Module module = context.findModule("opendaylight-sal-dom-broker-impl",
+            QName.parseRevision("2013-10-28")).get();
 
         final Set<AugmentationSchema> augmentations = module.getAugmentations();
         boolean checked = false;
@@ -61,16 +60,12 @@ public class ControllerStmtParserTest {
                     final ContainerSchemaNode containerNode = (ContainerSchemaNode) dataNode2;
                     final DataSchemaNode leaf = containerNode
                             .getDataChildByName(QName.create(module.getQNameModule(), "type"));
-                    final List<UnknownSchemaNode> unknownSchemaNodes = leaf
-                            .getUnknownSchemaNodes();
+                    final List<UnknownSchemaNode> unknownSchemaNodes = leaf.getUnknownSchemaNodes();
                     assertEquals(1, unknownSchemaNodes.size());
 
-                    final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes
-                            .get(0);
-                    assertEquals("dom-async-data-broker", unknownSchemaNode
-                            .getQName().getLocalName());
-                    assertEquals(unknownSchemaNode.getQName(),
-                            unknownSchemaNode.getPath().getLastComponent());
+                    final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.get(0);
+                    assertEquals("dom-async-data-broker", unknownSchemaNode.getQName().getLocalName());
+                    assertEquals(unknownSchemaNode.getQName(), unknownSchemaNode.getPath().getLastComponent());
 
                     checked = true;
                 }
@@ -81,12 +76,9 @@ public class ControllerStmtParserTest {
 
     private static void configModuleTest(final SchemaContext context) throws ParseException,
             URISyntaxException {
-        final Module configModule = context.findModuleByName("config", QName.parseRevision("2013-04-05"));
-        assertNotNull(configModule);
-
-        final Module module = context.findModuleByName(
-                "opendaylight-sal-dom-broker-impl", QName.parseRevision("2013-10-28"));
-        assertNotNull(module);
+        final Module configModule = context.findModule("config", QName.parseRevision("2013-04-05")).get();
+        final Module module = context.findModule("opendaylight-sal-dom-broker-impl",
+            QName.parseRevision("2013-10-28")).get();
 
         final DataSchemaNode dataNode = configModule.getDataChildByName(QName.create(configModule.getQNameModule(),
             "modules"));
@@ -105,8 +97,7 @@ public class ControllerStmtParserTest {
         assertTrue(dataChildChoice instanceof ChoiceSchemaNode);
 
         final ChoiceSchemaNode confChoice = (ChoiceSchemaNode) dataChildChoice;
-        final ChoiceCaseNode caseNodeByName = confChoice
-                .getCaseNodeByName("dom-broker-impl");
+        final ChoiceCaseNode caseNodeByName = confChoice.getCaseNodeByName("dom-broker-impl");
 
         assertNotNull(caseNodeByName);
         final DataSchemaNode dataNode2 = caseNodeByName
@@ -115,20 +106,16 @@ public class ControllerStmtParserTest {
 
         final ContainerSchemaNode containerNode = (ContainerSchemaNode) dataNode2;
         final DataSchemaNode leaf = containerNode.getDataChildByName(QName.create(module.getQNameModule(), "type"));
-        final List<UnknownSchemaNode> unknownSchemaNodes = leaf
-                .getUnknownSchemaNodes();
+        final List<UnknownSchemaNode> unknownSchemaNodes = leaf.getUnknownSchemaNodes();
 
         assertEquals(1, unknownSchemaNodes.size());
 
         final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.get(0);
 
-        assertEquals(unknownSchemaNode.getQName(), unknownSchemaNode.getPath()
-                .getLastComponent());
-        assertEquals("dom-async-data-broker", unknownSchemaNode.getQName()
-                .getLocalName());
+        assertEquals(unknownSchemaNode.getQName(), unknownSchemaNode.getPath().getLastComponent());
+        assertEquals("dom-async-data-broker", unknownSchemaNode.getQName().getLocalName());
 
-        final ChoiceCaseNode domInmemoryDataBroker = confChoice
-                .getCaseNodeByName("dom-inmemory-data-broker");
+        final ChoiceCaseNode domInmemoryDataBroker = confChoice.getCaseNodeByName("dom-inmemory-data-broker");
 
         assertNotNull(domInmemoryDataBroker);
         final DataSchemaNode schemaService = domInmemoryDataBroker
index e04d1f723b0262618add27762a4894d76021ea61..c6b22da80057a37341cbcb8e27b5e2a5d2badedd 100644 (file)
@@ -82,7 +82,7 @@ public class DeclaredStatementsTest {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSources(anyxmlStmtModule);
         assertNotNull(schemaContext);
 
-        final Module testModule = schemaContext.findModuleByName("anyxml-declared-test", null);
+        final Module testModule = schemaContext.findModules("anyxml-declared-test").iterator().next();
         assertNotNull(testModule);
 
         final AnyXmlSchemaNode anyxmlSchemaNode = (AnyXmlSchemaNode) testModule.getDataChildByName(
@@ -152,7 +152,7 @@ public class DeclaredStatementsTest {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSources(choiceStmtModule);
         assertNotNull(schemaContext);
 
-        final Module testModule = schemaContext.findModuleByName("choice-declared-test", null);
+        final Module testModule = schemaContext.findModules("choice-declared-test").iterator().next();
         assertNotNull(testModule);
 
         final ChoiceSchemaNode choiceSchemaNode = (ChoiceSchemaNode) testModule.getDataChildByName(
@@ -219,7 +219,7 @@ public class DeclaredStatementsTest {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSources(augmentStmtModule);
         assertNotNull(schemaContext);
 
-        final Module testModule = schemaContext.findModuleByName("augment-declared-test", null);
+        final Module testModule = schemaContext.findModules("augment-declared-test").iterator().next();
         assertNotNull(testModule);
 
         final Set<AugmentationSchema> augmentationSchemas = testModule.getAugmentations();
@@ -249,7 +249,7 @@ public class DeclaredStatementsTest {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSources(parentModule, childModule);
         assertNotNull(schemaContext);
 
-        final Module testModule = schemaContext.findModuleByName("parent-module-declared-test", null);
+        final Module testModule = schemaContext.findModules("parent-module-declared-test").iterator().next();
         assertNotNull(testModule);
 
         final ModuleStatement moduleStatement = ((ModuleEffectiveStatementImpl) testModule).getDeclared();
@@ -305,7 +305,7 @@ public class DeclaredStatementsTest {
 
         final Date revision = QName.parseRevision("2016-09-28");
 
-        final Module testModule = schemaContext.findModuleByName("root-module-declared-test", revision);
+        final Module testModule = schemaContext.findModule("root-module-declared-test", revision).get();
         assertNotNull(testModule);
 
         final ModuleStatement moduleStatement = ((ModuleEffectiveStatementImpl) testModule).getDeclared();
@@ -376,7 +376,7 @@ public class DeclaredStatementsTest {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSources(containerStmtModule);
         assertNotNull(schemaContext);
 
-        final Module testModule = schemaContext.findModuleByName("container-declared-test", null);
+        final Module testModule = schemaContext.findModules("container-declared-test").iterator().next();
         assertNotNull(testModule);
 
         final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) testModule.getDataChildByName(
index cb2f8cacbc355a5d21f4a4039b1c09af1c5520b0..5121250fefd7ba84ad14e0a3f346babc576ef20d 100644 (file)
@@ -18,7 +18,6 @@ import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResour
 
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
-import java.util.Date;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
@@ -44,11 +43,7 @@ public class DeviationResolutionTest {
                 "/deviation-resolution-test/deviation-not-supported");
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2017-01-20");
-
-        final Module importedModule = schemaContext.findModuleByName("imported", revision);
-        assertNotNull(importedModule);
-
+        final Module importedModule = schemaContext.findModule("imported", QName.parseRevision("2017-01-20")).get();
         final ContainerSchemaNode myContA = (ContainerSchemaNode) importedModule.getDataChildByName(
                 QName.create(importedModule.getQNameModule(), "my-cont-a"));
         assertNotNull(myContA);
@@ -76,9 +71,7 @@ public class DeviationResolutionTest {
                 sourceForResource("/deviation-resolution-test/deviation-add/bar.yang"));
         assertNotNull(schemaContext);
 
-        final Module barModule = schemaContext.findModuleByName("bar", QName.parseRevision("2017-01-20"));
-        assertNotNull(barModule);
-
+        final Module barModule = schemaContext.findModule("bar", QName.parseRevision("2017-01-20")).get();
         final LeafListSchemaNode myLeafList = (LeafListSchemaNode) barModule.getDataChildByName(
                 QName.create(barModule.getQNameModule(), "my-leaf-list"));
         assertNotNull(myLeafList);
@@ -122,9 +115,7 @@ public class DeviationResolutionTest {
                 sourceForResource("/deviation-resolution-test/deviation-replace/bar.yang"));
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2017-01-20");
-
-        final Module barModule = schemaContext.findModuleByName("bar", revision);
+        final Module barModule = schemaContext.findModule("bar", QName.parseRevision("2017-01-20")).get();
         assertNotNull(barModule);
 
         final LeafSchemaNode myLeaf = (LeafSchemaNode) barModule.getDataChildByName(
@@ -187,11 +178,7 @@ public class DeviationResolutionTest {
                 sourceForResource("/deviation-resolution-test/deviation-delete/bar.yang"));
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2017-01-20");
-
-        final Module barModule = schemaContext.findModuleByName("bar", revision);
-        assertNotNull(barModule);
-
+        final Module barModule = schemaContext.findModule("bar", QName.parseRevision("2017-01-20")).get();
         final LeafSchemaNode myLeaf = (LeafSchemaNode) barModule.getDataChildByName(
                 QName.create(barModule.getQNameModule(), "my-leaf"));
         assertNotNull(myLeaf);
index 91bc1bea840522433a2c137bf59d2b0988a13b0d..8fd0d4c75bb45fd4deecc144531031361c59fffe 100644 (file)
@@ -15,7 +15,6 @@ import static org.junit.Assert.assertTrue;
 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
 
 import java.text.ParseException;
-import java.util.Date;
 import java.util.List;
 import java.util.Set;
 import org.junit.Test;
@@ -46,11 +45,7 @@ public class DeviationStmtTest {
         final SchemaContext schemaContext = reactor.buildEffective();
         assertNotNull(schemaContext);
 
-        Date revision = QName.parseRevision("2016-06-23");
-
-        Module testModule = schemaContext.findModuleByName("foo", revision);
-        assertNotNull(testModule);
-
+        Module testModule = schemaContext.findModule("foo", QName.parseRevision("2016-06-23")).get();
         Set<Deviation> deviations = testModule.getDeviations();
         assertEquals(4, deviations.size());
 
@@ -87,8 +82,7 @@ public class DeviationStmtTest {
             }
         }
 
-        revision = QName.parseRevision("2016-09-22");
-        testModule = schemaContext.findModuleByName("bar", revision);
+        testModule = schemaContext.findModule("bar", QName.parseRevision("2016-09-22")).get();
         assertNotNull(testModule);
 
         deviations = testModule.getDeviations();
index 629c935399785545d91926baa460b7392d819555..f7b343daf8271b74e790b394fb631c049a4d9148 100644 (file)
@@ -52,7 +52,7 @@ public class EffectiveBuildTest {
 
         assertNotNull(result);
 
-        Module simpleModule = result.findModuleByName("simple-module", null);
+        Module simpleModule = result.findModules("simple-module").iterator().next();
         assertNotNull(simpleModule);
 
         QName q1 = QName.create(SIMPLE_MODULE_QNAME, "root-container");
index d309b864ff2609b3018ac064eba8ba2ea172155c..098022c1d44b25ac8220427946e709be662b87f7 100644 (file)
@@ -63,11 +63,7 @@ public class EffectiveIdentityTest {
 
         assertNotNull(result);
 
-        Module module = result.findModuleByName("identity-test",
-                SimpleDateFormatUtil.DEFAULT_DATE_REV);
-
-        assertNotNull(module);
-
+        Module module = result.findModule("identity-test", SimpleDateFormatUtil.DEFAULT_DATE_REV).get();
         Set<IdentitySchemaNode> identities = module.getIdentities();
 
         assertNotNull(identities);
index f4bf5aeeeeb51f0160f8967cc887921600085629..f5455fbc1262684544098ee53b16e84234b2bb19 100644 (file)
@@ -69,7 +69,7 @@ public class EffectiveModuleTest {
 
         assertNotNull(result);
 
-        Module rootModule = result.findModuleByName("root", null);
+        Module rootModule = result.findModules("root").iterator().next();
         assertNotNull(rootModule);
 
         assertEquals("root-pref", rootModule.getPrefix());
index 8e978ff49e145d698b9a712dd79f59708112de2a..057bf5f91ce48ab73dde2eac98774a5665b3d6b4 100644 (file)
@@ -174,12 +174,10 @@ public class EffectiveModulesAndSubmodulesTest {
 
     private static void findModulesSubTest(final SchemaContext result, final Module root, final Module imported)
             throws URISyntaxException {
-        final Module foundRoot = result.findModuleByName("root-module",
-                SimpleDateFormatUtil.DEFAULT_DATE_REV);
-        final Set<Module> foundRoots = result.findModuleByNamespace(new URI(
-                "root-module"));
-        final Module foundRoot3 = result.findModuleByNamespaceAndRevision(new URI(
-                "root-module"), SimpleDateFormatUtil.DEFAULT_DATE_REV);
+        final Module foundRoot = result.findModule("root-module", SimpleDateFormatUtil.DEFAULT_DATE_REV).get();
+        final Set<Module> foundRoots = result.findModules(new URI("root-module"));
+        final Module foundRoot3 = result.findModule(new URI("root-module"), SimpleDateFormatUtil.DEFAULT_DATE_REV)
+                .get();
 
         assertNotNull(foundRoot);
         assertNotNull(foundRoots);
@@ -193,13 +191,10 @@ public class EffectiveModulesAndSubmodulesTest {
         assertEquals(root, foundRoot2);
         assertEquals(root, foundRoot3);
 
-        final Module foundImported = result.findModuleByName("imported-module",
-                SimpleDateFormatUtil.DEFAULT_DATE_REV);
-        final Set<Module> foundImporteds = result.findModuleByNamespace(new URI(
-                "imported-module"));
-        final Module foundImported3 = result.findModuleByNamespaceAndRevision(
-                new URI("imported-module"),
-                SimpleDateFormatUtil.DEFAULT_DATE_REV);
+        final Module foundImported = result.findModule("imported-module", SimpleDateFormatUtil.DEFAULT_DATE_REV).get();
+        final Set<Module> foundImporteds = result.findModules(new URI("imported-module"));
+        final Module foundImported3 = result.findModule(new URI("imported-module"),
+            SimpleDateFormatUtil.DEFAULT_DATE_REV).get();
 
         assertNotNull(foundImported);
         assertNotNull(foundImporteds);
index 7fe454a080793910af6e0f65d4506074baf4cb4e..b677e71812a468db12ddff0096d03876b930a49c 100644 (file)
@@ -78,10 +78,9 @@ public class EffectiveSchemaContextTest {
 
         assertNull(schemaContext.getDataChildByName(QName.create("foo-namespace", "2016-09-21", "foo-cont")));
 
-        assertNull(schemaContext.findModuleByName("foo", QName.parseRevision("2016-08-21")));
-        assertNull(schemaContext.findModuleByNamespaceAndRevision(null, QName.parseRevision("2016-09-21")));
-        assertNull(schemaContext.findModuleByNamespaceAndRevision(URI.create("foo-namespace"),
-            QName.parseRevision("2016-08-21")));
+        assertFalse(schemaContext.findModule("foo", QName.parseRevision("2016-08-21")).isPresent());
+        assertFalse(schemaContext.findModule(URI.create("foo-namespace"), QName.parseRevision("2016-08-21"))
+            .isPresent());
 
         assertFalse(schemaContext.isAugmenting());
         assertFalse(schemaContext.isAddedByUses());
@@ -98,9 +97,7 @@ public class EffectiveSchemaContextTest {
         assertNotNull(schemaContext.getAvailableAugmentations());
         assertTrue(schemaContext.getAvailableAugmentations().isEmpty());
 
-        Module fooModule = schemaContext.findModuleByName("foo", QName.parseRevision("2016-09-21"));
-        assertNotNull(fooModule);
-
+        Module fooModule = schemaContext.findModule("foo", QName.parseRevision("2016-09-21")).get();
         assertEquals(3, schemaContext.getModules().size());
         assertEquals(3, ((EffectiveSchemaContext) schemaContext).getRootDeclaredStatements().size());
         assertEquals(3,((EffectiveSchemaContext) schemaContext).getRootEffectiveStatements().size());
index 499221c666554ba30998c28168697db3e008a76d..0f81593d7976a6b92e1059ef644465f36895a432 100644 (file)
@@ -64,7 +64,7 @@ public class EffectiveStatementTypeTest {
         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
         reactor.addSource(IMPORTED_MODULE);
         effectiveSchemaContext = reactor.buildEffective();
-        types = effectiveSchemaContext.findModuleByName("types", null);
+        types = effectiveSchemaContext.findModules("types").iterator().next();
         assertNotNull(types);
     }
 
index 0dd0ea4c73ced7c183ffd1dd703e224ac2cf5a0d..6650d6b9642f715d7ffac9b180a078d3634c898c 100644 (file)
@@ -42,7 +42,7 @@ public class ExtensionStmtTest {
         final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("bar", null);
+        final Module testModule = result.findModules("bar").iterator().next();
         assertNotNull(testModule);
 
         assertEquals(1, testModule.getExtensionSchemaNodes().size());
@@ -62,7 +62,7 @@ public class ExtensionStmtTest {
         final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        final Module testModule1 = result.findModuleByName("ext-typedef", null);
+        final Module testModule1 = result.findModules("ext-typedef").iterator().next();
         assertNotNull(testModule1);
 
         assertEquals(1, testModule1.getExtensionSchemaNodes().size());
@@ -70,7 +70,7 @@ public class ExtensionStmtTest {
         final List<ExtensionDefinition> extensions = testModule1.getExtensionSchemaNodes();
         final ExtensionDefinition extensionDefinition = extensions.get(0);
 
-        final Module testModule2 = result.findModuleByName("ext-use", null);
+        final Module testModule2 = result.findModules("ext-use").iterator().next();
         assertNotNull(testModule2);
 
         final LeafSchemaNode leaf = (LeafSchemaNode) testModule2.getDataChildByName(QName.create(testModule2.getQNameModule(), "value"));
index ea23c159de546795d5a341fa8780c7dc3e86128e..8492782a584698b0883b80b4a3744acc6a1441d3 100644 (file)
@@ -53,7 +53,7 @@ public class GroupingAndUsesStmtTest {
         final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("baz", null);
+        final Module testModule = result.findModules("baz").iterator().next();
         assertNotNull(testModule);
 
         final Set<GroupingDefinition> groupings = testModule.getGroupings();
@@ -95,7 +95,7 @@ public class GroupingAndUsesStmtTest {
         final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("foo", null);
+        final Module testModule = result.findModules("foo").iterator().next();
         assertNotNull(testModule);
 
         final Set<UsesNode> usesNodes = testModule.getUses();
index 840c84394a3c2cd5d43a20f78360fae45fb1387d..850fb919d337fe707052170192bbac576d95396d 100644 (file)
@@ -89,7 +89,7 @@ public class IdentityStmtTest {
         SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        Module testModule = result.findModuleByName("legal-chained-identity-test", null);
+        Module testModule = result.findModules("legal-chained-identity-test").iterator().next();
         assertNotNull(testModule);
 
         Set<IdentitySchemaNode> identities = testModule.getIdentities();
@@ -121,7 +121,7 @@ public class IdentityStmtTest {
         SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        Module testModule = result.findModuleByName("duplicate-identity-test", null);
+        Module testModule = result.findModules("duplicate-identity-test").iterator().next();
         Set<IdentitySchemaNode> identities = testModule.getIdentities();
         assertEquals(1, identities.size());
     }
index 49b3cf6ee107075ebba56a8ce19430771b9ffe48..a4c6cc1e5d8cfa3cfe7d3324d7678ae781e32d6e 100644 (file)
@@ -47,7 +47,7 @@ public class IfFeatureResolutionTest {
         final SchemaContext schemaContext = reactor.buildEffective();
         assertNotNull(schemaContext);
 
-        final Module testModule = schemaContext.findModuleByName("foo", null);
+        final Module testModule = schemaContext.findModules("foo").iterator().next();
         assertNotNull(testModule);
 
         assertEquals(9, testModule.getChildNodes().size());
@@ -153,7 +153,7 @@ public class IfFeatureResolutionTest {
         final SchemaContext schemaContext = reactor.buildEffective();
         assertNotNull(schemaContext);
 
-        final Module testModule = schemaContext.findModuleByName("foo", null);
+        final Module testModule = schemaContext.findModules("foo").iterator().next();
         assertNotNull(testModule);
 
         assertEquals(11, testModule.getChildNodes().size());
@@ -281,7 +281,7 @@ public class IfFeatureResolutionTest {
         final SchemaContext schemaContext = reactor.buildEffective();
         assertNotNull(schemaContext);
 
-        final Module testModule = schemaContext.findModuleByName("foo", null);
+        final Module testModule = schemaContext.findModules("foo").iterator().next();
         assertNotNull(testModule);
 
         assertEquals(6, testModule.getChildNodes().size());
index 1d05c7e0861b1b14d855b764a771678075ce2f82..10fbdbccace73a313a413808cc83ae280effa087 100644 (file)
@@ -17,6 +17,7 @@ import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResour
 
 import java.util.Iterator;
 import java.util.Set;
+import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -37,15 +38,18 @@ public class IncludedStmtsTest {
     private static final StatementStreamSource CHILD_MODULE = sourceForResource(
             "/included-statements-test/child-module.yang");
 
-    @Test
-    public void includedTypedefsTest() throws ReactorException {
+    private SchemaContext result;
+
+    @Before
+    public void setup() throws ReactorException {
         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
         reactor.addSources(ROOT_MODULE, CHILD_MODULE);
+        result = reactor.buildEffective();
+    }
 
-        final SchemaContext result = reactor.buildEffective();
-        assertNotNull(result);
-
-        final Module testModule = result.findModuleByName("root-module", null);
+    @Test
+    public void includedTypedefsTest() {
+        final Module testModule = result.findModules("root-module").iterator().next();
         assertNotNull(testModule);
 
         final Set<TypeDefinition<?>> typedefs = testModule.getTypeDefinitions();
@@ -61,14 +65,8 @@ public class IncludedStmtsTest {
     }
 
     @Test
-    public void includedFeaturesTest() throws ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(ROOT_MODULE, CHILD_MODULE);
-
-        final SchemaContext result = reactor.buildEffective();
-        assertNotNull(result);
-
-        final Module testModule = result.findModuleByName("root-module", null);
+    public void includedFeaturesTest() {
+        final Module testModule = result.findModules("root-module").iterator().next();
         assertNotNull(testModule);
 
         final Set<FeatureDefinition> features = testModule.getFeatures();
@@ -82,14 +80,8 @@ public class IncludedStmtsTest {
     }
 
     @Test
-    public void includedContainersAndListsTest() throws ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(ROOT_MODULE, CHILD_MODULE);
-
-        final SchemaContext result = reactor.buildEffective();
-        assertNotNull(result);
-
-        final Module testModule = result.findModuleByName("root-module", null);
+    public void includedContainersAndListsTest() {
+        final Module testModule = result.findModules("root-module").iterator().next();
         assertNotNull(testModule);
 
         ContainerSchemaNode cont = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "parent-container"));
@@ -105,14 +97,8 @@ public class IncludedStmtsTest {
     }
 
     @Test
-    public void submoduleNamespaceTest() throws ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(ROOT_MODULE, CHILD_MODULE);
-
-        final SchemaContext result = reactor.buildEffective();
-        assertNotNull(result);
-
-        final Module testModule = result.findModuleByName("root-module", null);
+    public void submoduleNamespaceTest() {
+        final Module testModule = result.findModules("root-module").iterator().next();
         assertNotNull(testModule);
 
         final Module subModule = testModule.getSubmodules().iterator().next();
index 430a3d4b32ca526d281cf2f1bdd0b6fbb0fdadd6..e9d8befcb77f5e259fe4aa89958d90d3631136f1 100644 (file)
@@ -39,10 +39,11 @@ public class ListTest {
         final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("list-test", null);
+        final Module testModule = result.findModules("list-test").iterator().next();
         assertNotNull(testModule);
 
-        final ListSchemaNode list = (ListSchemaNode) testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "simple-list"));
+        final ListSchemaNode list = (ListSchemaNode) testModule.getDataChildByName(
+            QName.create(testModule.getQNameModule(), "simple-list"));
         assertNotNull(list);
 
         assertTrue(list.isUserOrdered());
@@ -58,7 +59,8 @@ public class ListTest {
 
         assertEquals(5, list.getChildNodes().size());
 
-        LeafSchemaNode leaf = (LeafSchemaNode) list.getDataChildByName(QName.create(testModule.getQNameModule(), "key1"));
+        LeafSchemaNode leaf = (LeafSchemaNode) list.getDataChildByName(QName.create(testModule.getQNameModule(),
+            "key1"));
         assertNotNull(leaf);
         assertTrue(leaf.getConstraints().isMandatory());
         assertEquals("int32", leaf.getType().getQName().getLocalName());
@@ -79,7 +81,8 @@ public class ListTest {
         assertEquals("young-leaf", leaf.getType().getQName().getLocalName());
         assertEquals("default-value", leaf.getDefault());
 
-        final LeafListSchemaNode leafList = (LeafListSchemaNode) list.getDataChildByName(QName.create(testModule.getQNameModule(), "list-of-leaves"));
+        final LeafListSchemaNode leafList = (LeafListSchemaNode) list.getDataChildByName(
+            QName.create(testModule.getQNameModule(), "list-of-leaves"));
         assertNotNull(leafList);
         assertTrue(leafList.getConstraints().isMandatory());
         assertTrue(leafList.isUserOrdered());
index 3304d0b9a71ef0aba07567282c5ba8165db206c0..1fe90cff613d653563e066825510f52c784beb58 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
@@ -139,9 +140,9 @@ public class MoreRevisionsTest {
     private static void checkContentFullTest(final SchemaContext context) {
         URI yangTypesNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types");
 
-        Date rev20100924 = QName.parseRevision("2010-09-24");
-        Date rev20130516 = QName.parseRevision("2013-05-16");
-        Date rev20130715 = QName.parseRevision("2013-07-15");
+        final Date rev20100924 = QName.parseRevision("2010-09-24");
+        final Date rev20130516 = QName.parseRevision("2013-05-16");
+        final Date rev20130715 = QName.parseRevision("2013-07-15");
 
         final QNameModule yangTypes_20100924 = QNameModule.create(yangTypesNS, rev20100924);
         final QNameModule yangTypes_20130516 = QNameModule.create(yangTypesNS, rev20130516);
@@ -151,14 +152,9 @@ public class MoreRevisionsTest {
         final QName dateTimeTypeDef_20130516 = QName.create(yangTypes_20130516, "date-and-time");
         final QName dateTimeTypeDef_20130715 = QName.create(yangTypes_20130715, "date-and-time");
 
-        Module yangTypesModule_20100924 = context.findModuleByName("ietf-yang-types", rev20100924);
-        Module yangTypesModule_20130516 = context.findModuleByName("ietf-yang-types", rev20130516);
-        Module yangTypesModule_20130715 = context.findModuleByName("ietf-yang-types", rev20130715);
-
-        assertNotNull(yangTypesModule_20100924);
-        assertNotNull(yangTypesModule_20130516);
-        assertNotNull(yangTypesModule_20130715);
-
+        Module yangTypesModule_20100924 = context.findModule("ietf-yang-types", rev20100924).get();
+        Module yangTypesModule_20130516 = context.findModule("ietf-yang-types", rev20130516).get();
+        Module yangTypesModule_20130715 = context.findModule("ietf-yang-types", rev20130715).get();
         assertTrue(findTypeDef(yangTypesModule_20100924, dateTimeTypeDef_20100924));
         assertTrue(findTypeDef(yangTypesModule_20130516, dateTimeTypeDef_20130516));
         assertTrue(findTypeDef(yangTypesModule_20130715, dateTimeTypeDef_20130715));
@@ -171,9 +167,7 @@ public class MoreRevisionsTest {
             final QName dateTimeTypeDef_20100924) {
         Date rev20121115 = QName.parseRevision("2012-11-15");
 
-        Module interfacesModule_20121115 = context.findModuleByName("ietf-interfaces", rev20121115);
-        assertNotNull(interfacesModule_20121115);
-
+        Module interfacesModule_20121115 = context.findModule("ietf-interfaces", rev20121115).get();
         Set<ModuleImport> imports = interfacesModule_20121115.getImports();
         assertEquals(1, imports.size());
         ModuleImport interfacesImport = imports.iterator().next();
@@ -185,9 +179,7 @@ public class MoreRevisionsTest {
             final Date rev20130715, final QName dateTimeTypeDef_20130715) {
         Date rev20101004 = QName.parseRevision("2010-10-04");
 
-        Module monitoringModule_20101004 = context.findModuleByName("ietf-netconf-monitoring", rev20101004);
-        assertNotNull(monitoringModule_20101004);
-
+        Module monitoringModule_20101004 = context.findModule("ietf-netconf-monitoring", rev20101004).get();
         Set<ModuleImport> imports = monitoringModule_20101004.getImports();
         assertEquals(2, imports.size());
         for (ModuleImport monitoringImport : imports) {
@@ -211,9 +203,9 @@ public class MoreRevisionsTest {
     private static void checkContentSimpleTest(final SchemaContext context) {
         URI yangTypesNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types");
 
-        Date rev20100924 = QName.parseRevision("2010-09-24");
-        Date rev20130516 = QName.parseRevision("2013-05-16");
-        Date rev20130715 = QName.parseRevision("2013-07-15");
+        final Date rev20100924 = QName.parseRevision("2010-09-24");
+        final Date rev20130516 = QName.parseRevision("2013-05-16");
+        final Date rev20130715 = QName.parseRevision("2013-07-15");
 
         final QNameModule yangTypes_20100924 = QNameModule.create(yangTypesNS, rev20100924);
         final QNameModule yangTypes_20130516 = QNameModule.create(yangTypesNS, rev20130516);
@@ -223,14 +215,9 @@ public class MoreRevisionsTest {
         final QName dateTimeTypeDef_20130516 = QName.create(yangTypes_20130516, "date-and-time");
         final QName dateTimeTypeDef_20130715 = QName.create(yangTypes_20130715, "date-and-time");
 
-        Module yangTypesModule_20100924 = context.findModuleByName("ietf-yang-types", rev20100924);
-        Module yangTypesModule_20130516 = context.findModuleByName("ietf-yang-types", rev20130516);
-        Module yangTypesModule_20130715 = context.findModuleByName("ietf-yang-types", rev20130715);
-
-        assertNotNull(yangTypesModule_20100924);
-        assertNotNull(yangTypesModule_20130516);
-        assertNotNull(yangTypesModule_20130715);
-
+        Module yangTypesModule_20100924 = context.findModule("ietf-yang-types", rev20100924).get();
+        Module yangTypesModule_20130516 = context.findModule("ietf-yang-types", rev20130516).get();
+        Module yangTypesModule_20130715 = context.findModule("ietf-yang-types", rev20130715).get();
         assertTrue(findTypeDef(yangTypesModule_20100924, dateTimeTypeDef_20100924));
         assertTrue(findTypeDef(yangTypesModule_20130516, dateTimeTypeDef_20130516));
         assertTrue(findTypeDef(yangTypesModule_20130715, dateTimeTypeDef_20130715));
@@ -246,11 +233,8 @@ public class MoreRevisionsTest {
         final QNameModule interfacesNS_20121115 = QNameModule.create(interfacesNS, rev20121115);
         QName lastChange = QName.create(interfacesNS_20121115, "last-change");
 
-        Module interfacesModule_20121115 = context.findModuleByName("ietf-interfaces", rev20121115);
-        assertNotNull(interfacesModule_20121115);
-
-        DataSchemaNode leafLastChange = interfacesModule_20121115
-                .getDataChildByName(lastChange);
+        Module interfacesModule_20121115 = context.findModule("ietf-interfaces", rev20121115).get();
+        DataSchemaNode leafLastChange = interfacesModule_20121115.getDataChildByName(lastChange);
         assertNotNull(leafLastChange);
 
         assertTrue(leafLastChange instanceof LeafSchemaNode);
@@ -267,13 +251,11 @@ public class MoreRevisionsTest {
     private static void checkNetconfMonitoringModuleSimpleTest(final SchemaContext context,
             final Date rev20130715, final QName dateTimeTypeDef_20130715) {
         URI monitoringNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring");
-        Date rev19700101 = QName.parseRevision("1970-01-01");
-        final QNameModule monitoring_19700101 = QNameModule.create(monitoringNS, rev19700101);
+        final QNameModule monitoring_19700101 = QNameModule.create(monitoringNS, SimpleDateFormatUtil.DEFAULT_DATE_REV);
         QName lockedTime = QName.create(monitoring_19700101, "locked-time");
 
-        Module monitoringModule_19700101 = context.findModuleByName("ietf-netconf-monitoring", rev19700101);
-        assertNotNull(monitoringModule_19700101);
-
+        Module monitoringModule_19700101 = context.findModule("ietf-netconf-monitoring",
+            SimpleDateFormatUtil.DEFAULT_DATE_REV).get();
         DataSchemaNode leafLockedTime = monitoringModule_19700101.getDataChildByName(lockedTime);
         assertNotNull(leafLockedTime);
 
index a3dc7e346a34eb9622cf627896ec91dd9f7b2279..2f3390d1e9ca113538b578690a6615f9da1de715 100644 (file)
@@ -42,7 +42,7 @@ public class MustAndWhenStmtTest {
         final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("must-test", null);
+        final Module testModule = result.findModules("must-test").iterator().next();
         assertNotNull(testModule);
 
         final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(
@@ -76,7 +76,7 @@ public class MustAndWhenStmtTest {
         final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("when-test", null);
+        final Module testModule = result.findModules("when-test").iterator().next();
         assertNotNull(testModule);
 
         final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(
index 1d70134ec7b8bc2c9f6dcde01026914d7c994b0a..21245d0f1ee708f972ed1abd44b95ab11f723f70 100644 (file)
@@ -38,7 +38,7 @@ public class NotificationStmtTest {
         final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("baz", null);
+        final Module testModule = result.findModules("baz").iterator().next();
         assertNotNull(testModule);
 
         final Set<NotificationDefinition> notifications = testModule.getNotifications();
index 9a02d0f0f4fd87a2d5ddb5b864bb406710160fe3..2e2709ab2cfeca73e9d3574ef1c0041a95049003 100644 (file)
@@ -15,7 +15,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
 
-import java.util.Date;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -45,9 +44,7 @@ public class RpcStmtTest {
         final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("baz", null);
-        assertNotNull(testModule);
-
+        final Module testModule = result.findModules("baz").iterator().next();
         assertEquals(1, testModule.getRpcs().size());
 
         final RpcDefinition rpc = testModule.getRpcs().iterator().next();
@@ -71,9 +68,7 @@ public class RpcStmtTest {
         anyXml = (AnyXmlSchemaNode) output.getDataChildByName(QName.create(testModule.getQNameModule(), "data"));
         assertNotNull(anyXml);
 
-        final Module fooModule = result.findModuleByName("foo", QName.parseRevision("2016-09-23"));
-        assertNotNull(fooModule);
-
+        final Module fooModule = result.findModule("foo", QName.parseRevision("2016-09-23")).get();
         final Set<RpcDefinition> rpcs = fooModule.getRpcs();
         assertEquals(2, rpcs.size());
 
@@ -111,11 +106,7 @@ public class RpcStmtTest {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rpc-stmt-test/bar.yang");
         assertNotNull(schemaContext);
 
-        final Date revision = QName.parseRevision("2016-11-25");
-
-        final Module barModule = schemaContext.findModuleByName("bar", revision);
-        assertNotNull(barModule);
-
+        final Module barModule = schemaContext.findModule("bar", QName.parseRevision("2016-11-25")).get();
         final Set<RpcDefinition> rpcs = barModule.getRpcs();
         assertEquals(1, rpcs.size());
 
index 61f2615f5b7bf570b5ec5c6fc82e8ce686954c23..6e653514b3862ffc9f29ef80cd600539617147b2 100644 (file)
@@ -208,16 +208,19 @@ public class StmtTestUtils {
         return parseYinSources(statementParserMode, sources);
     }
 
-    public static SchemaContext parseYinSources(final StatementParserMode statementParserMode, final StatementStreamSource... sources)
+    public static SchemaContext parseYinSources(final StatementParserMode statementParserMode,
+            final StatementStreamSource... sources)
             throws ReactorException {
 
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode);
+        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+                .newBuild(statementParserMode);
         reactor.addSources(sources);
 
         return reactor.buildEffective();
     }
 
-    public static Module findImportedModule(final SchemaContext context, final Module rootModule, final String importedModuleName) {
+    public static Module findImportedModule(final SchemaContext context, final Module rootModule,
+            final String importedModuleName) {
         ModuleImport requestedModuleImport = null;
         final Set<ModuleImport> rootImports = rootModule.getImports();
         for (final ModuleImport moduleImport : rootImports) {
@@ -227,12 +230,12 @@ public class StmtTestUtils {
             }
         }
 
-        final Module importedModule = context.findModuleByName(requestedModuleImport.getModuleName(),
-                requestedModuleImport.getRevision());
-        return importedModule;
+        return context.findModule(requestedModuleImport.getModuleName(), requestedModuleImport.getRevision())
+                .orElse(null);
     }
 
-    public static SchemaContext parseYangSources(final String yangFilesDirectoryPath, final String yangLibsDirectoryPath)
+    public static SchemaContext parseYangSources(final String yangFilesDirectoryPath,
+            final String yangLibsDirectoryPath)
             throws URISyntaxException, ReactorException, IOException, YangSyntaxErrorException {
         return parseYangSources(yangFilesDirectoryPath, yangLibsDirectoryPath, null);
     }
index 1acd69f75ec0eb7578f47f8e658f9543639848dd..49b48f06a97fa032422cac4958584a8bfa3ea3fb 100644 (file)
@@ -16,15 +16,12 @@ import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResour
 
 import com.google.common.collect.ImmutableSet;
 import java.net.URI;
-import java.text.ParseException;
 import java.util.Date;
 import java.util.List;
 import java.util.Set;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
 import org.opendaylight.yangtools.yang.model.api.Module;
@@ -57,18 +54,10 @@ public class YangDataExtensionTest {
     private static final StatementStreamSource IETF_RESTCONF_MODULE = sourceForResource(
             "/yang-data-extension-test/ietf-restconf.yang");
 
-    private static Date revision;
-    private static QNameModule fooModule;
-    private static QName myYangDataA;
-    private static QName myYangDataB;
-
-    @BeforeClass
-    public static void setup() throws ParseException {
-        revision = SimpleDateFormatUtil.getRevisionFormat().parse("2017-06-01");
-        fooModule = QNameModule.create(URI.create("foo"), revision);
-        myYangDataA = QName.create(fooModule, "my-yang-data-a");
-        myYangDataB = QName.create(fooModule, "my-yang-data-b");
-    }
+    private static final Date REVISION = QName.parseRevision("2017-06-01");
+    private static final QNameModule FOO_QNAMEMODULE = QNameModule.create(URI.create("foo"), REVISION);
+    private static final QName MY_YANG_DATA_A = QName.create(FOO_QNAMEMODULE, "my-yang-data-a");
+    private static final QName MY_YANG_DATA_B = QName.create(FOO_QNAMEMODULE, "my-yang-data-b");
 
     @Test
     public void testYangData() throws Exception {
@@ -78,9 +67,7 @@ public class YangDataExtensionTest {
         final Set<ExtensionDefinition> extensions = schemaContext.getExtensions();
         assertEquals(1, extensions.size());
 
-        final Module foo = schemaContext.findModuleByName("foo", revision);
-        assertNotNull(foo);
-
+        final Module foo = schemaContext.findModule(FOO_QNAMEMODULE).get();
         final List<UnknownSchemaNode> unknownSchemaNodes = foo.getUnknownSchemaNodes();
         assertEquals(2, unknownSchemaNodes.size());
 
@@ -89,9 +76,9 @@ public class YangDataExtensionTest {
         for (final UnknownSchemaNode unknownSchemaNode : unknownSchemaNodes) {
             assertTrue(unknownSchemaNode instanceof YangDataSchemaNode);
             final YangDataSchemaNode yangDataSchemaNode = (YangDataSchemaNode) unknownSchemaNode;
-            if (myYangDataA.equals(yangDataSchemaNode.getQName())) {
+            if (MY_YANG_DATA_A.equals(yangDataSchemaNode.getQName())) {
                 myYangDataANode = yangDataSchemaNode;
-            } else if (myYangDataB.equals(yangDataSchemaNode.getQName())) {
+            } else if (MY_YANG_DATA_B.equals(yangDataSchemaNode.getQName())) {
                 myYangDataBNode = yangDataSchemaNode;
             }
         }
@@ -108,9 +95,7 @@ public class YangDataExtensionTest {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSources(BAZ_MODULE, IETF_RESTCONF_MODULE);
         assertNotNull(schemaContext);
 
-        final Module baz = schemaContext.findModuleByName("baz", revision);
-        assertNotNull(baz);
-
+        final Module baz = schemaContext.findModule("baz", REVISION).get();
         final List<UnknownSchemaNode> unknownSchemaNodes = baz.getUnknownSchemaNodes();
         assertEquals(1, unknownSchemaNodes.size());
 
@@ -141,9 +126,7 @@ public class YangDataExtensionTest {
         final SchemaContext schemaContext = reactor.buildEffective();
         assertNotNull(schemaContext);
 
-        final Module foobar = schemaContext.findModuleByName("foobar", revision);
-        assertNotNull(foobar);
-
+        final Module foobar = schemaContext.findModule("foobar", REVISION).get();
         final List<UnknownSchemaNode> unknownSchemaNodes = foobar.getUnknownSchemaNodes();
         assertEquals(1, unknownSchemaNodes.size());
 
@@ -169,8 +152,7 @@ public class YangDataExtensionTest {
         final SchemaContext schemaContext = StmtTestUtils.parseYangSources(BAR_MODULE, IETF_RESTCONF_MODULE);
         assertNotNull(schemaContext);
 
-        final Module bar = schemaContext.findModuleByName("bar", revision);
-        assertNotNull(bar);
+        final Module bar = schemaContext.findModule("bar", REVISION).get();
         final ContainerSchemaNode cont = (ContainerSchemaNode) bar.getDataChildByName(
                 QName.create(bar.getQNameModule(), "cont"));
         assertNotNull(cont);
index 6e999b4471c868f36b4cd205252c33e997b7e2d1..f26fd2a6d13b3443e8ebd7374ec7781e4cccff34 100644 (file)
@@ -78,9 +78,7 @@ public class YangParserWithContextTest {
 
         final SchemaContext context = reactor.buildEffective();
 
-        final Module module = context.findModuleByName("test1", QName.parseRevision("2013-06-18"));
-        assertNotNull(module);
-
+        final Module module = context.findModule("test1", QName.parseRevision("2013-06-18")).get();
         final LeafSchemaNode leaf = (LeafSchemaNode) module.getDataChildByName(QName.create(module.getQNameModule(),
                 "id"));
 
@@ -114,11 +112,8 @@ public class YangParserWithContextTest {
         reactor.addSources(BAZ, FOO, BAR, SUBFOO, test2);
         final SchemaContext context = reactor.buildEffective();
 
-        final Module testModule = context.findModuleByName("test2", QName.parseRevision("2013-06-18"));
-        assertNotNull(testModule);
-
-        final Module contextModule = context.findModuleByNamespace(URI.create("urn:opendaylight.baz")).iterator()
-                .next();
+        final Module testModule = context.findModule("test2", QName.parseRevision("2013-06-18")).get();
+        final Module contextModule = context.findModules(URI.create("urn:opendaylight.baz")).iterator().next();
         assertNotNull(contextModule);
         final Set<GroupingDefinition> groupings = contextModule.getGroupings();
         assertEquals(1, groupings.size());
@@ -224,8 +219,7 @@ public class YangParserWithContextTest {
         reactor.addSources(BAZ, FOO, BAR, SUBFOO, test2);
         final SchemaContext context = reactor.buildEffective();
 
-        final Module module = context.findModuleByName("test2", QName.parseRevision("2013-06-18"));
-        assertNotNull(module);
+        final Module module = context.findModule("test2", QName.parseRevision("2013-06-18")).get();
         final ContainerSchemaNode peer = (ContainerSchemaNode) module.getDataChildByName(QName.create(
                 module.getQNameModule(), "peer"));
         final ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName(QName.create(
@@ -302,9 +296,7 @@ public class YangParserWithContextTest {
         reactor.addSources(types, test3);
         final SchemaContext context = reactor.buildEffective();
 
-        final Module module = context.findModuleByName("test3", QName.parseRevision("2013-06-18"));
-        assertNotNull(module);
-
+        final Module module = context.findModule("test3", QName.parseRevision("2013-06-18")).get();
         final Set<IdentitySchemaNode> identities = module.getIdentities();
         assertEquals(1, identities.size());
 
@@ -334,9 +326,7 @@ public class YangParserWithContextTest {
 
         final SchemaContext context = reactor.buildEffective();
 
-        final Module module = context.findModuleByName("test3", QName.parseRevision("2013-06-18"));
-        assertNotNull(module);
-
+        final Module module = context.findModule("test3", QName.parseRevision("2013-06-18")).get();
         final ContainerSchemaNode network = (ContainerSchemaNode) module.getDataChildByName(QName.create(
                 module.getQNameModule(), "network"));
         final List<UnknownSchemaNode> unknownNodes = network.getUnknownSchemaNodes();
@@ -398,9 +388,7 @@ public class YangParserWithContextTest {
         reactor.addSources(bar, deviationTest);
         final SchemaContext context = reactor.buildEffective();
 
-        final Module testModule = context.findModuleByName("deviation-test", QName.parseRevision("2013-02-27"));
-        assertNotNull(testModule);
-
+        final Module testModule = context.findModule("deviation-test", QName.parseRevision("2013-02-27")).get();
         final Set<Deviation> deviations = testModule.getDeviations();
         assertEquals(1, deviations.size());
         final Deviation dev = deviations.iterator().next();
index 58c478e6d2e6a8c3341f5f07f5403829e5acde98..8f01027159d6dc6b935ec6988b3388b6e2a48d65 100644 (file)
@@ -29,9 +29,8 @@ public class OpenconfigVersionBorderCaseTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
@@ -45,9 +44,8 @@ public class OpenconfigVersionBorderCaseTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
@@ -61,9 +59,8 @@ public class OpenconfigVersionBorderCaseTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
index 0485f75f657ceee9c8a7a86f50ac54e3f3a713e8..4c748add576d4959958a9d1c8f0e2e510bbe07af 100644 (file)
@@ -40,9 +40,9 @@ public class OpenconfigVersionComplexTest {
     private static void verifySchemaContextTest1(final SchemaContext context) {
         assertNotNull(context);
 
-        final Module foo = context.findModuleByNamespace(URI.create("foo")).iterator().next();
-        final Module semVer = context.findModuleByNamespace(
-            URI.create("http://openconfig.net/yang/openconfig-ext")).iterator().next();
+        final Module foo = context.findModules(URI.create("foo")).iterator().next();
+        final Module semVer = context.findModules(URI.create("http://openconfig.net/yang/openconfig-ext"))
+                .iterator().next();
 
         // check module versions
         assertEquals(SemVer.valueOf("1.3.95"), semVer.getSemanticVersion().get());
@@ -86,9 +86,9 @@ public class OpenconfigVersionComplexTest {
     private static void verifySchemaContextTest2(final SchemaContext context) {
         assertNotNull(context);
 
-        final Module foo = context.findModuleByNamespace(URI.create("foo")).iterator().next();
-        final Module semVer = context.findModuleByNamespace(URI.create(
-            "http://openconfig.net/yang/openconfig-ext")).iterator().next();
+        final Module foo = context.findModules(URI.create("foo")).iterator().next();
+        final Module semVer = context.findModules(URI.create("http://openconfig.net/yang/openconfig-ext"))
+                .iterator().next();
 
         // check module versions
         assertEquals(SemVer.valueOf("2.5.50"), semVer.getSemanticVersion().get());
index 4ef4a678546dc8ea60e2e3fdbb11a9f6844f62b6..988173f93af5731a99ffa71db2e9fbe16e548052 100644 (file)
@@ -30,8 +30,8 @@ public class OpenconfigVersionDefaultsTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module bar = context.findModules(new URI("bar")).iterator().next();
 
         assertEquals(Optional.empty(), foo.getSemanticVersion());
         assertEquals(Optional.empty(), bar.getSemanticVersion());
@@ -43,8 +43,8 @@ public class OpenconfigVersionDefaultsTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module bar = context.findModules(new URI("bar")).iterator().next();
 
         assertEquals(Optional.empty(), foo.getSemanticVersion());
         assertEquals(SemVer.valueOf("0.99.99"), bar.getSemanticVersion().get());
index bd653a9303689e6b746c688eeb70dc34b2650342..65e75068e43f78318afaf205da7d7986a7c8959b 100644 (file)
@@ -26,10 +26,9 @@ public class OpenconfigVersionIgnoringRevisionTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module bar = context.findModules(new URI("bar")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
@@ -42,9 +41,8 @@ public class OpenconfigVersionIgnoringRevisionTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
         Module bar = StmtTestUtils.findImportedModule(context, foo, "bar");
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
index 00e0a8cf1e162b675e22c68f78fdc0684466cf93..da4420e245e3231ab59df36a3751eccf7f552b5c 100644 (file)
@@ -29,8 +29,7 @@ public class OpenconfigVersionImportTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("1.0.0"), semVer.getSemanticVersion().get());
     }
index 2b1a42757d6e305e5e21bb390162e88e352e7ba6..a26f0027c804dbd127e7b4f952e4345e79906bf2 100644 (file)
@@ -55,9 +55,8 @@ public class OpenconfigVersionMultipleImportTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
@@ -71,9 +70,8 @@ public class OpenconfigVersionMultipleImportTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
@@ -92,8 +90,6 @@ public class OpenconfigVersionMultipleImportTest {
             }
         }
 
-        Module importedModule = context.findModuleByName(requestedModuleImport.getModuleName(),
-                requestedModuleImport.getRevision());
-        return importedModule;
+        return context.findModule(requestedModuleImport.getModuleName(), requestedModuleImport.getRevision()).get();
     }
 }
index bdd2772b479fd457ec8ea9fa36bf40ad2461c603..55dc9991853bfcbbb509264306e682068df5279d 100644 (file)
@@ -26,10 +26,9 @@ public class OpenconfigVersionPositionTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module bar = context.findModules(new URI("bar")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
@@ -42,10 +41,9 @@ public class OpenconfigVersionPositionTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module bar = context.findModules(new URI("bar")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
@@ -58,10 +56,9 @@ public class OpenconfigVersionPositionTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module bar = context.findModules(new URI("bar")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
index 700a5be7bc3c9e4c42bc1f0333bae951691eeff4..c568e020176adeea79caf21dd9fe47f535727a2f 100644 (file)
@@ -34,10 +34,9 @@ public class OpenconfigVersionTest {
             StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module bar = context.findModules(new URI("bar")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
@@ -50,10 +49,9 @@ public class OpenconfigVersionTest {
             StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module bar = context.findModules(new URI("bar")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
@@ -66,9 +64,8 @@ public class OpenconfigVersionTest {
             StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
@@ -80,9 +77,8 @@ public class OpenconfigVersionTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
@@ -96,9 +92,8 @@ public class OpenconfigVersionTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
@@ -109,7 +104,8 @@ public class OpenconfigVersionTest {
     @Test
     public void basicImportErrTest1() throws Exception {
         try {
-            StmtTestUtils.parseYangSources("/openconfig-version/basic-import-invalid-1", StatementParserMode.SEMVER_MODE);
+            StmtTestUtils.parseYangSources("/openconfig-version/basic-import-invalid-1",
+                StatementParserMode.SEMVER_MODE);
             fail("Test should fail due to invalid openconfig version");
         } catch (ReactorException e) {
             assertTrue(e.getCause().getCause().getMessage()
@@ -134,9 +130,8 @@ public class OpenconfigVersionTest {
             StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
-        Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(new URI("foo")).iterator().next();
+        Module semVer = context.findModules(new URI("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("2016.1.1"), foo.getSemanticVersion().get());
index 1206e40eb37037eec34c12d940515134efd2fdaf..dc0d1f5d5adc8f03f9edac271501bba444aa5972 100644 (file)
@@ -33,10 +33,9 @@ public class YinOpenconfigVersionTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(URI.create("foo")).iterator().next();
-        Module bar = context.findModuleByNamespace(URI.create("bar")).iterator().next();
-        Module semVer = context.findModuleByNamespace(URI.create("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(URI.create("foo")).iterator().next();
+        Module bar = context.findModules(URI.create("bar")).iterator().next();
+        Module semVer = context.findModules(URI.create("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
@@ -49,9 +48,8 @@ public class YinOpenconfigVersionTest {
                 StatementParserMode.SEMVER_MODE);
         assertNotNull(context);
 
-        Module foo = context.findModuleByNamespace(URI.create("foo")).iterator().next();
-        Module semVer = context.findModuleByNamespace(URI.create("http://openconfig.net/yang/openconfig-ext"))
-                .iterator().next();
+        Module foo = context.findModules(URI.create("foo")).iterator().next();
+        Module semVer = context.findModules(URI.create("http://openconfig.net/yang/openconfig-ext")).iterator().next();
 
         assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get());
         assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get());
index 3ded08a8bc1a8e9799a1f86b648d2432e82f3234..3c8ff18beedc4a398bf28b7eb7ae536915054aa1 100644 (file)
@@ -12,8 +12,6 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.annotations.Beta;
 import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Verify;
-import java.util.Date;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 
@@ -40,9 +38,7 @@ public abstract class NamespaceKeyCriterion<K> {
 
         @Override
         public ModuleIdentifier select(final ModuleIdentifier first, final ModuleIdentifier second) {
-            final Date firstRev = Verify.verifyNotNull(first.getRevision());
-            final Date secondRev = Verify.verifyNotNull(second.getRevision());
-            return firstRev.compareTo(secondRev) >= 0 ? first : second;
+            return ModuleIdentifier.compareRevisions(first.getRevision(), second.getRevision()) >= 0 ? first : second;
         }
 
         @Override