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 {
23 private final @Nullable Object directUsers;
25 public DefaultGroupingRuntimeType(final GeneratedType bindingType, final GroupingEffectiveStatement statement,
26 final List<RuntimeType> children, final List<? extends CompositeRuntimeType> directUsers) {
27 super(bindingType, statement, children);
28 this.directUsers = switch (directUsers.size()) {
30 case 1 -> Objects.requireNonNull(directUsers.get(0));
31 default -> directUsers.stream().map(Objects::requireNonNull).toArray(CompositeRuntimeType[]::new);
36 public List<CompositeRuntimeType> directUsers() {
37 final var local = directUsers;
40 } else if (local instanceof CompositeRuntimeType[] array) {
41 return Collections.unmodifiableList(Arrays.asList(array));
43 return List.of((CompositeRuntimeType) local);