92d861832269592c358697d6b0ca7fd5523c4bc7
[mdsal.git] / binding / mdsal-binding-generator / src / main / java / org / opendaylight / mdsal / binding / generator / impl / rt / DefaultModuleRuntimeType.java
1 /*
2  * Copyright (c) 2021 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.mdsal.binding.generator.impl.rt;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.ImmutableMap;
14 import com.google.common.collect.Maps;
15 import java.util.List;
16 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
17 import org.opendaylight.mdsal.binding.runtime.api.ModuleRuntimeType;
18 import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
19 import org.opendaylight.mdsal.binding.runtime.api.YangDataRuntimeType;
20 import org.opendaylight.yangtools.yang.common.YangDataName;
21 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
22
23 @Beta
24 public final class DefaultModuleRuntimeType extends AbstractCompositeRuntimeType<ModuleEffectiveStatement>
25         implements ModuleRuntimeType {
26     private final ImmutableMap<YangDataName, YangDataRuntimeType> yangDataChildren;
27
28     public DefaultModuleRuntimeType(final GeneratedType bindingType, final ModuleEffectiveStatement statement,
29             final List<RuntimeType> children, final List<YangDataRuntimeType> yangDataChildren) {
30         super(bindingType, statement, children);
31         this.yangDataChildren = Maps.uniqueIndex(yangDataChildren, type -> type.statement().argument());
32     }
33
34     @Override
35     public YangDataRuntimeType yangDataChild(final YangDataName templateName) {
36         return yangDataChildren.get(requireNonNull(templateName));
37     }
38 }