package org.opendaylight.mdsal.yanglib.rfc8525;
import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.base.Verify.verifyNotNull;
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;
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<>();
YangLibraryContentBuilderImpl(final BindingCodecTree codecTree) {
this.codecTree = Objects.requireNonNull(codecTree);
- this.codec = verifyNotNull(codecTree.getSubtreeCodec(InstanceIdentifier.create(YangLibrary.class)));
+ codec = codecTree.getDataObjectCodec(InstanceIdentifier.create(YangLibrary.class));
}
@Override
// 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));
.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) {