2 * Copyright (c) 2015 Cisco Systems, Inc. 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.yangtools.yang.model.api;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.ImmutableList;
14 import java.util.Collection;
15 import java.util.List;
16 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
22 * A ChoiceSchemaNode defines a set of alternatives. It consists of a number of branches defined as
23 * ChoiceCaseSchemaNode objects.
25 public interface ChoiceSchemaNode extends DataSchemaNode, AugmentationTarget, MandatoryAware,
26 EffectiveStatementEquivalent<ChoiceEffectiveStatement> {
28 * Returns cases of choice, keyed by their {@link SchemaNode#getQName()}. Returned map does not contain null keys
31 * @return set of ChoiceCaseNode objects defined in this node which represents set of arguments of the YANG
32 * <code>case</code> substatement of the <code>choice</code> statement.
34 Collection<? extends @NonNull CaseSchemaNode> getCases();
37 * Returns the concrete case according to specified Q name.
40 * QName of sought Choice Case Node
41 * @return child case node of this Choice if child with given name is present, empty otherwise.
42 * @throws NullPointerException if qname is null
44 default Optional<? extends CaseSchemaNode> findCase(final QName qname) {
45 requireNonNull(qname);
46 return getCases().stream().filter(node -> qname.equals(node.getQName())).findFirst();
50 * Returns the concrete cases according to specified name, disregarding their namespace.
53 * local name of sought child as String
54 * @return child case nodes matching specified local name, empty list if no match is found.
55 * @throws NullPointerException if localname is null
58 default List<? extends @NonNull CaseSchemaNode> findCaseNodes(final String localname) {
59 return getCases().stream().filter(node -> localname.equals(node.getQName().getLocalName()))
60 .collect(ImmutableList.toImmutableList());
64 * Find a specific data schema child, if present. This method searches among its {@link CaseSchemaNode}s,
65 * potentially recursing to nested choices.
68 * QName of sought data schema node
69 * @return Matching node, or empty if no match is found
70 * @throws NullPointerException if qname is null
73 default Optional<DataSchemaNode> findDataSchemaChild(final QName qname) {
74 requireNonNull(qname);
75 for (CaseSchemaNode caseNode : getCases()) {
76 final Optional<DataSchemaNode> child = caseNode.findDataChildByName(qname);
77 if (child.isPresent()) {
82 return Optional.empty();
86 * Returns name of case which is in the choice specified as default.
88 * @return string with the name of case which is specified in the argument of the YANG <code>default</code>
89 * substatement of <code>choice</code> statement.
91 Optional<CaseSchemaNode> getDefaultCase();