Remove duplicate documentation
[mdsal.git] / binding / mdsal-binding-generator / src / main / java / org / opendaylight / mdsal / binding / generator / impl / rt / DefaultGroupingRuntimeType.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 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;
20
21 public final class DefaultGroupingRuntimeType extends AbstractCompositeRuntimeType<GroupingEffectiveStatement>
22         implements GroupingRuntimeType {
23     private final @Nullable Object directUsers;
24
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()) {
29             case 0 -> null;
30             case 1 -> Objects.requireNonNull(directUsers.get(0));
31             default -> directUsers.stream().map(Objects::requireNonNull).toArray(CompositeRuntimeType[]::new);
32         };
33     }
34
35     @Override
36     public List<CompositeRuntimeType> directUsers() {
37         final var local = directUsers;
38         if (local == null) {
39             return List.of();
40         } else if (local instanceof CompositeRuntimeType[] array) {
41             return Collections.unmodifiableList(Arrays.asList(array));
42         } else {
43             return List.of((CompositeRuntimeType) local);
44         }
45     }
46 }