summaryrefslogtreecommitdiffstats
path: root/netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsEffectiveModuleContext.java
blob: 35fffa052b92df418dce37cdc0c585a7d0709722 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.restconf.common.util;

import static com.google.common.base.Verify.verify;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.spi.SimpleSchemaContext;

final class OperationsEffectiveModuleContext extends SimpleSchemaContext implements EffectiveModelContext {
    private final Map<QNameModule, ModuleEffectiveStatement> modules;

    OperationsEffectiveModuleContext(final Set<Module> modules) {
        super(modules);
        this.modules = modules.stream()
                .map(module -> {
                    verify(module instanceof ModuleEffectiveStatement, "Module %s is not an effective statement");
                    return (ModuleEffectiveStatement) module;
                })
                .collect(ImmutableMap.toImmutableMap(ModuleEffectiveStatement::localQNameModule, Function.identity()));
    }

    @Override
    public Map<QNameModule, ModuleEffectiveStatement> getModuleStatements() {
        return modules;
    }
}