02bba8aa7d040cce29f873cf6a489d77efa8f587
[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 com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableList;
12 import java.util.List;
13 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
14 import org.opendaylight.mdsal.binding.runtime.api.ModuleRuntimeType;
15 import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
16 import org.opendaylight.mdsal.binding.runtime.api.YangDataRuntimeType;
17 import org.opendaylight.yangtools.yang.common.YangDataName;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
19
20 @Beta
21 public final class DefaultModuleRuntimeType extends AbstractCompositeRuntimeType<ModuleEffectiveStatement>
22         implements ModuleRuntimeType {
23     private final ImmutableList<YangDataRuntimeType> yangDataChildren;
24
25     public DefaultModuleRuntimeType(final GeneratedType bindingType, final ModuleEffectiveStatement statement,
26             final List<RuntimeType> children) {
27         super(bindingType, statement, children);
28         yangDataChildren = children.stream()
29             .filter(YangDataRuntimeType.class::isInstance)
30             .map(YangDataRuntimeType.class::cast)
31             .collect(ImmutableList.toImmutableList());
32     }
33
34     @Override
35     public YangDataRuntimeType yangDataChild(final YangDataName templateName) {
36         if (statement().localQNameModule().equals(templateName.module())) {
37             final var name = templateName.name();
38             for (var child : yangDataChildren) {
39                 if (name.equals(child.statement().argument())) {
40                     return child;
41                 }
42             }
43         }
44         return null;
45     }
46 }