84af4cc2f841084bdaa9652e79614a2325819bd2
[mdsal.git] / binding / mdsal-binding-generator / src / main / java / org / opendaylight / mdsal / binding / generator / impl / rt / DefaultActionRuntimeType.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 java.util.List;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
14 import org.opendaylight.mdsal.binding.runtime.api.ActionRuntimeType;
15 import org.opendaylight.mdsal.binding.runtime.api.AugmentRuntimeType;
16 import org.opendaylight.mdsal.binding.runtime.api.InputRuntimeType;
17 import org.opendaylight.mdsal.binding.runtime.api.OutputRuntimeType;
18 import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
20
21 @Beta
22 public final class DefaultActionRuntimeType extends AbstractCompositeRuntimeType<ActionEffectiveStatement>
23         implements ActionRuntimeType {
24     private final @NonNull InputRuntimeType input;
25     private final @NonNull OutputRuntimeType output;
26
27     public DefaultActionRuntimeType(final GeneratedType bindingType, final ActionEffectiveStatement statement,
28             final List<RuntimeType> children, final List<AugmentRuntimeType> augments) {
29         super(bindingType, statement, children, augments);
30         input = child(children, InputRuntimeType.class);
31         output = child(children, OutputRuntimeType.class);
32     }
33
34     @Override
35     public InputRuntimeType input() {
36         return input;
37     }
38
39     @Override
40     public OutputRuntimeType output() {
41         return output;
42     }
43
44     private static <T extends RuntimeType> @NonNull T child(final List<RuntimeType> list, final Class<T> clazz) {
45         return list.stream().filter(clazz::isInstance).map(clazz::cast).findFirst().orElseThrow();
46     }
47 }