3dcaede4d0cb87db257ba032e4d2dbbcc7d67a09
[yangtools.git] / model / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / stmt / SchemaTreeRoot.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.yangtools.yang.model.api.stmt;
9
10 import static org.opendaylight.yangtools.yang.model.api.stmt.DefaultMethodHelpers.filterOptional;
11
12 import com.google.common.annotations.Beta;
13 import java.util.Optional;
14 import org.eclipse.jdt.annotation.NonNull;
15
16 /**
17  * Common interface implemented by entities which act as the root of the {@code schema tree} and are able to resolve an
18  * {@code SchemaNodeIdentifier} to a {@link SchemaTreeEffectiveStatement}.
19  */
20 @Beta
21 public interface SchemaTreeRoot {
22     /**
23      * Find a {@code schema tree} node based on its schema node identifier.
24      *
25      * @param path Absolute schema node identifier
26      * @return Found node, or empty
27      * @throws NullPointerException if {@code path} is null
28      */
29     @NonNull Optional<SchemaTreeEffectiveStatement<?>> findSchemaTreeNode(@NonNull SchemaNodeIdentifier path);
30
31     /**
32      * Find a {@code schema tree} node based on its schema node identifier.
33      *
34      * @implSpec
35      *     Default implementation defers to {@link #findSchemaTreeNode(SchemaNodeIdentifier)} and filters the result
36      *     using provided class.
37      *
38      * @param <T> requested node type
39      * @param type Request node class
40      * @param path Absolute schema node identifier
41      * @return Found node, or empty
42      * @throws NullPointerException if any argument is null
43      */
44     default <T> @NonNull Optional<T> findSchemaTreeNode(final @NonNull Class<T> type,
45             final @NonNull SchemaNodeIdentifier path) {
46         return filterOptional(type, findSchemaTreeNode(path));
47     }
48 }