2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.generator.impl.rt;
10 import java.util.Arrays;
11 import java.util.Collections;
12 import java.util.List;
13 import java.util.Objects;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
16 import org.opendaylight.mdsal.binding.runtime.api.CompositeRuntimeType;
17 import org.opendaylight.mdsal.binding.runtime.api.GroupingRuntimeType;
18 import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
19 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
21 public final class DefaultGroupingRuntimeType extends AbstractCompositeRuntimeType<GroupingEffectiveStatement>
22 implements GroupingRuntimeType {
24 * These are vectors towards concrete instantiations of this type -- i.e. the manifestation in the effective data
25 * tree. Each item in this list represents either:
27 * <li>a concrete instantiation, or<li>
28 * <li>another {@link GroupingRuntimeType}</li>
30 * We use these vectors to create {@link #instantiations()}.
32 private final @Nullable Object instantiationVectors;
34 public DefaultGroupingRuntimeType(final GeneratedType bindingType, final GroupingEffectiveStatement statement,
35 final List<RuntimeType> children, final List<? extends CompositeRuntimeType> instantiationVectors) {
36 super(bindingType, statement, children);
37 this.instantiationVectors = switch (instantiationVectors.size()) {
39 case 1 -> Objects.requireNonNull(instantiationVectors.get(0));
40 default -> instantiationVectors.stream().map(Objects::requireNonNull).toArray(CompositeRuntimeType[]::new);
45 public List<CompositeRuntimeType> directUsers() {
46 final var local = instantiationVectors;
49 } else if (local instanceof CompositeRuntimeType[] array) {
50 return Collections.unmodifiableList(Arrays.asList(array));
52 return List.of((CompositeRuntimeType) local);