2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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.stmt;
10 import static org.opendaylight.yangtools.yang.model.api.stmt.DefaultMethodHelpers.filterOptional;
12 import com.google.common.annotations.Beta;
13 import java.util.Optional;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.common.SchemaNodeIdentifier;
18 * Common interface implemented by entities which act as the root of the {@code schema tree} and are able to resolve an
19 * {@code SchemaNodeIdentifier} to a {@link SchemaTreeEffectiveStatement}.
22 public interface SchemaTreeRoot {
24 * Find a {@code schema tree} node based on its schema node identifier.
26 * @param path Absolute schema node identifier
27 * @return Found node, or empty
28 * @throws NullPointerException if {@code path} is null
30 @NonNull Optional<SchemaTreeEffectiveStatement<?>> findSchemaTreeNode(@NonNull SchemaNodeIdentifier path);
33 * Find a {@code schema tree} node based on its schema node identifier.
36 * Default implementation defers to {@link #findSchemaTreeNode(SchemaNodeIdentifier)} and filters the result
37 * using provided class.
39 * @param <T> requested node type
40 * @param type Request node class
41 * @param path Absolute schema node identifier
42 * @return Found node, or empty
43 * @throws NullPointerException if any argument is null
45 default <T> @NonNull Optional<T> findSchemaTreeNode(final @NonNull Class<T> type,
46 final @NonNull SchemaNodeIdentifier path) {
47 return filterOptional(type, findSchemaTreeNode(path));