Map system-ordered leaf-lists to Set<T>
[mdsal.git] / yanglib / mdsal-yanglib-rfc8525 / src / main / java / org / opendaylight / mdsal / yanglib / rfc8525 / YangLibraryContentBuilderImpl.java
index c15a1e62541d37bc98cb42193e213b25148ebfcb..5f4c79f478b28a1f7410996907be092d4aff7621 100644 (file)
@@ -14,7 +14,6 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
-import java.util.function.Function;
 import java.util.stream.Collectors;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
@@ -27,19 +26,19 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.librar
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.Module;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.ModuleBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.module.Submodule;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.module.SubmoduleBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.ModuleSet;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.ModuleSetBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.ModuleSetKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.DatastoreIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
-class YangLibraryContentBuilderImpl implements YangLibraryContentBuilder {
+final class YangLibraryContentBuilderImpl implements YangLibraryContentBuilder {
     private static final String MODULE_SET_NAME = "ODL_modules";
 
     private final Map<DatastoreIdentifier, EffectiveModelContext> datastores = new HashMap<>();
@@ -50,7 +49,7 @@ class YangLibraryContentBuilderImpl implements YangLibraryContentBuilder {
 
     YangLibraryContentBuilderImpl(final BindingCodecTree codecTree) {
         this.codecTree = Objects.requireNonNull(codecTree);
-        this.codec = verifyNotNull(codecTree.getSubtreeCodec(InstanceIdentifier.create(YangLibrary.class)));
+        codec = verifyNotNull(codecTree.getSubtreeCodec(InstanceIdentifier.create(YangLibrary.class)));
     }
 
     @Override
@@ -85,10 +84,10 @@ class YangLibraryContentBuilderImpl implements YangLibraryContentBuilder {
         // Two-step process: we first build the content and then use hashCode() to generate module-set-id
         final YangLibraryBuilder builder = new YangLibraryBuilder().setContentId("");
         final ModuleSetBuilder moduleSetBuilder = new ModuleSetBuilder()
-                .setModule(modelContext.getModules().stream()
-                        .map(this::buildModule)
-                        .collect(Collectors.toUnmodifiableMap(Module::key, Function.identity())))
-                .setName(MODULE_SET_NAME);
+            .setModule(modelContext.getModules().stream()
+                .map(YangLibraryContentBuilderImpl::buildModule)
+                .collect(BindingMap.toMap()))
+            .setName(MODULE_SET_NAME);
         final ModuleSet moduleSet = moduleSetBuilder.build();
 
         builder.setModuleSet(Map.of(new ModuleSetKey(moduleSet.getName()), moduleSet));
@@ -96,21 +95,21 @@ class YangLibraryContentBuilderImpl implements YangLibraryContentBuilder {
             .build());
     }
 
-    private Module buildModule(final org.opendaylight.yangtools.yang.model.api.Module module) {
+    private static Module buildModule(final org.opendaylight.yangtools.yang.model.api.Module module) {
         return new ModuleBuilder()
-                .setName(new YangIdentifier(module.getName()))
-                .setNamespace(new Uri(module.getQNameModule().getNamespace().toString()))
-                .setRevision(convertRevision(module.getRevision()))
-                .setSubmodule(module.getSubmodules().stream()
-                        .map(submodule -> new SubmoduleBuilder()
-                                .setName(new YangIdentifier(submodule.getName()))
-                                .setRevision(convertRevision(submodule.getRevision()))
-                                .build())
-                        .collect(Collectors.toUnmodifiableMap(Submodule::key, Function.identity())))
-                .setFeature(module.getFeatures().stream()
-                        .map(feat -> new YangIdentifier(feat.getQName().getLocalName()))
-                        .collect(Collectors.toUnmodifiableList()))
-                .build();
+            .setName(new YangIdentifier(module.getName()))
+            .setNamespace(new Uri(module.getQNameModule().getNamespace().toString()))
+            .setRevision(convertRevision(module.getRevision()))
+            .setSubmodule(module.getSubmodules().stream()
+                .map(submodule -> new SubmoduleBuilder()
+                    .setName(new YangIdentifier(submodule.getName()))
+                    .setRevision(convertRevision(submodule.getRevision()))
+                    .build())
+                .collect(BindingMap.toMap()))
+            .setFeature(module.getFeatures().stream()
+                .map(feat -> new YangIdentifier(feat.getQName().getLocalName()))
+                .collect(Collectors.toUnmodifiableSet()))
+            .build();
     }
 
     private static RevisionIdentifier convertRevision(final Optional<Revision> revision) {