diff options
Diffstat (limited to 'netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsEffectiveModuleContext.java')
-rw-r--r-- | netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsEffectiveModuleContext.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsEffectiveModuleContext.java b/netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsEffectiveModuleContext.java new file mode 100644 index 0000000..35fffa0 --- /dev/null +++ b/netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsEffectiveModuleContext.java @@ -0,0 +1,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; + } +} |