Move restconf.common.util
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / impl / 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.nb.rfc8040.rests.services.impl;
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 @Deprecated(forRemoval = true, since = "4.0.0")
23 final class OperationsEffectiveModuleContext extends SimpleSchemaContext implements EffectiveModelContext {
24     private final ImmutableMap<QNameModule, ModuleEffectiveStatement> modules;
25
26     OperationsEffectiveModuleContext(final Set<Module> modules) {
27         super(modules);
28         this.modules = modules.stream()
29                 .map(module -> {
30                     verify(module instanceof ModuleEffectiveStatement, "Module %s is not an effective statement");
31                     return (ModuleEffectiveStatement) module;
32                 })
33                 .collect(ImmutableMap.toImmutableMap(ModuleEffectiveStatement::localQNameModule, Function.identity()));
34     }
35
36     @Override
37     public Map<QNameModule, ModuleEffectiveStatement> getModuleStatements() {
38         return modules;
39     }
40 }