Mass-promote EffectiveStatement captures
[yangtools.git] / model / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / stmt / DataTreeAwareEffectiveStatement.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, 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.yangtools.yang.model.api.stmt;
9
10 import static java.util.Objects.requireNonNull;
11 import static org.opendaylight.yangtools.yang.model.api.stmt.DefaultMethodHelpers.filterOptional;
12
13 import java.util.Optional;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18
19 /**
20  * Interface implemented by all {@link SchemaTreeAwareEffectiveStatement}s which can contain a {@code data tree} child.
21  *
22  * @param <A> Argument type
23  * @param <D> Class representing declared version of this statement.
24  */
25 public interface DataTreeAwareEffectiveStatement<A, D extends DeclaredStatement<A>>
26         extends SchemaTreeAwareEffectiveStatement<A, D> {
27     /**
28      * Namespace of {@code data node}s. This is a subtree of
29      * {@link SchemaTreeAwareEffectiveStatement.SchemaTreeNamespace} in that all data nodes are also schema nodes. The
30      * structure of the tree is different, though, as {@code choice} and {@code case} statements are glossed over and
31      * they do not contribute to the tree hierarchy -- only their children do.
32      *
33      * <p>
34      * This corresponds to the {@code data tree} view of a YANG-defined data.
35      */
36     @NonNullByDefault
37     abstract class DataTreeNamespace extends EffectiveStatementNamespace<DataTreeEffectiveStatement<?>> {
38         private DataTreeNamespace() {
39             // Should never be instantiated
40         }
41     }
42
43     /**
44      * Find a {@code data tree} child {@link DataTreeEffectiveStatement}, as identified by its QName argument.
45      *
46      * @param qname Child identifier
47      * @return Data tree child, or empty
48      * @throws NullPointerException if {@code qname} is {@code null}
49      */
50     default @NonNull Optional<DataTreeEffectiveStatement<?>> findDataTreeNode(final @NonNull QName qname) {
51         return get(DataTreeNamespace.class, requireNonNull(qname));
52     }
53
54     /**
55      * Find a {@code data tree} child {@link DataTreeEffectiveStatement}, as identified by its QName argument.
56      *
57      * @param <E> Effective substatement type
58      * @param type Effective substatement class
59      * @param qname Child identifier
60      * @return Data tree child, or empty
61      * @throws NullPointerException if any argument is {@code null}
62      */
63     default <E> @NonNull Optional<E> findDataTreeNode(final Class<E> type, final @NonNull QName qname) {
64         return filterOptional(type, findDataTreeNode(qname));
65     }
66 }