Clean up ietf-netconf-monitoring-extension
[netconf.git] / restconf / restconf-common / src / main / java / org / opendaylight / restconf / common / util / OperationsEffectiveModuleContext.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.common.util;
9
10 import static com.google.common.base.Verify.verify;
11
12 import com.google.common.collect.ImmutableMap;
13 import java.util.Map;
14 import java.util.Set;
15 import java.util.function.Function;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.spi.SimpleSchemaContext;
21
22 final class OperationsEffectiveModuleContext extends SimpleSchemaContext implements EffectiveModelContext {
23     private final Map<QNameModule, ModuleEffectiveStatement> modules;
24
25     OperationsEffectiveModuleContext(final Set<Module> modules) {
26         super(modules);
27         this.modules = modules.stream()
28                 .map(module -> {
29                     verify(module instanceof ModuleEffectiveStatement, "Module %s is not an effective statement");
30                     return (ModuleEffectiveStatement) module;
31                 })
32                 .collect(ImmutableMap.toImmutableMap(ModuleEffectiveStatement::localQNameModule, Function.identity()));
33     }
34
35     @Override
36     public Map<QNameModule, ModuleEffectiveStatement> getModuleStatements() {
37         return modules;
38     }
39 }