3a81294583c93805eaf0dd309b1f58f151a51c8f
[mdsal.git] / binding / mdsal-binding-generator / src / main / java / org / opendaylight / mdsal / binding / generator / impl / rt / DerivedChoiceRuntimeType.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.Collections2;
14 import com.google.common.collect.Iterables;
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.List;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
20 import org.opendaylight.mdsal.binding.runtime.api.AugmentRuntimeType;
21 import org.opendaylight.mdsal.binding.runtime.api.CaseRuntimeType;
22 import org.opendaylight.mdsal.binding.runtime.api.ChoiceRuntimeType;
23 import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
24 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
25
26 @Beta
27 public final class DerivedChoiceRuntimeType extends AbstractChoiceRuntimeType {
28     private final @NonNull ChoiceRuntimeType originalType;
29
30     public DerivedChoiceRuntimeType(final GeneratedType bindingType, final ChoiceEffectiveStatement statement,
31             final List<RuntimeType> children, final List<AugmentRuntimeType> augments,
32             final ChoiceRuntimeType originalType) {
33         super(bindingType, statement, children, augments);
34         this.originalType = requireNonNull(originalType);
35     }
36
37     @Override
38     public @NonNull ChoiceRuntimeType originalType() {
39         return originalType;
40     }
41
42     @Override
43     public Collection<CaseRuntimeType> additionalCaseChildren() {
44         final var myJavaTypes = Collections2.transform(validCaseChildren(), CaseRuntimeType::getIdentifier);
45         final var result = new ArrayList<CaseRuntimeType>();
46         for (var caseType : Iterables.concat(originalType.validCaseChildren(), originalType.additionalCaseChildren())) {
47             if (!myJavaTypes.contains(caseType.getIdentifier())) {
48                 result.add(caseType);
49             }
50         }
51         return result;
52     }
53 }