fd7c2986071076926af613ffea26745ee2a1f059
[yangtools.git] / yang / 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
12 import com.google.common.annotations.Beta;
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  * @author Robert Varga
25  */
26 @Beta
27 public interface DataTreeAwareEffectiveStatement<A, D extends DeclaredStatement<A>>
28         extends SchemaTreeAwareEffectiveStatement<A, D> {
29
30     /**
31      * Namespace of {@code data node}s. This is a subtree of {@link SchemaTreeAwareEffectiveStatement.Namespace} in that
32      * all data nodes are also schema nodes. The structure of the tree is different, though, as {@code choice}
33      * and {@code case} statements are glossed over and they do not contribute to the tree hierarchy -- only their
34      * children do.
35      *
36      * <p>
37      * This corresponds to the {@code data tree} view of a YANG-defined data.
38      *
39      * @param <T> Child statement type
40      */
41     @NonNullByDefault
42     abstract class Namespace<T extends DataTreeEffectiveStatement<?>> extends EffectiveStatementNamespace<T> {
43         private Namespace() {
44             // Should never be instantiated
45         }
46     }
47
48     /**
49      * Find a {@code data tree} child {@link DataTreeEffectiveStatement}, as identified by its QName argument.
50      *
51      * @param qname Child identifier
52      * @return Data tree child, or empty
53      * @throws NullPointerException if {@code qname} is null
54      */
55     default <E extends DataTreeEffectiveStatement<?>> @NonNull Optional<E> findDataTreeNode(
56             final @NonNull QName qname) {
57         return Optional.ofNullable((E)get(Namespace.class, requireNonNull(qname)));
58     }
59 }