Merge "Clean up netconf-parent root pom"
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / codecs / StringModuleInstanceIdentifierCodec.java
index 1fc2d83b343a965ac1a5922aa2322cdaeba23601..3dc7778782fb1e8a20ca70fc9157d3b2627b687e 100644 (file)
@@ -23,13 +23,13 @@ public final class StringModuleInstanceIdentifierCodec extends AbstractModuleStr
     private final SchemaContext context;
     private final String defaultPrefix;
 
-    public StringModuleInstanceIdentifierCodec(SchemaContext context) {
+    public StringModuleInstanceIdentifierCodec(final SchemaContext context) {
         this.context = Preconditions.checkNotNull(context);
         this.dataContextTree = DataSchemaContextTree.from(context);
         this.defaultPrefix = "";
     }
 
-    StringModuleInstanceIdentifierCodec(final SchemaContext context, @Nonnull final String defaultPrefix) {
+    public StringModuleInstanceIdentifierCodec(final SchemaContext context, @Nonnull final String defaultPrefix) {
         this.context = Preconditions.checkNotNull(context);
         this.dataContextTree = DataSchemaContextTree.from(context);
         this.defaultPrefix = defaultPrefix;
@@ -37,23 +37,19 @@ public final class StringModuleInstanceIdentifierCodec extends AbstractModuleStr
 
     @Override
     protected Module moduleForPrefix(@Nonnull final String prefix) {
-        if (prefix.isEmpty() && !this.defaultPrefix.isEmpty()) {
-            return this.context.findModuleByName(this.defaultPrefix, null);
-        } else {
-            return this.context.findModuleByName(prefix, null);
-        }
+        final String moduleName = prefix.isEmpty() && !defaultPrefix.isEmpty() ? defaultPrefix : prefix;
+        return context.findModules(moduleName).stream().findFirst().orElse(null);
     }
 
     @Nonnull
     @Override
-    protected DataSchemaContextTree getDataContextTree() {
+    public DataSchemaContextTree getDataContextTree() {
         return this.dataContextTree;
     }
 
     @Nullable
     @Override
     protected String prefixForNamespace(@Nonnull final URI namespace) {
-        final Module module = this.context.findModuleByNamespaceAndRevision(namespace, null);
-        return module == null ? null : module.getName();
+        return this.context.findModules(namespace).stream().findFirst().map(Module::getName).orElse(null);
     }
-}
\ No newline at end of file
+}