Populate model/ hierarchy
[yangtools.git] / model / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / SchemaTreeInference.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;
9
10 import com.google.common.collect.ImmutableList;
11 import java.util.List;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
14 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
15
16 /**
17  * An {@link EffectiveStatementInference} consisting purely of steps along the {@code schema tree} axis, so that it
18  * represents a {@code schema tree node} based on resolution of {@code absolute-schema-nodeid} as specified by
19  * <a href="https://tools.ietf.org/html/rfc7950#section-6.5">RFC7950 section 6.5</a>.
20  */
21 public interface SchemaTreeInference extends EffectiveStatementInference {
22     /**
23      * {@inheritDoc}
24      *
25      * <p>
26      * The statement path is always composed on {@link SchemaTreeEffectiveStatement}s and contains at least one element.
27      * The path is ordered from conceptual YANG root, i.e. the first element corresponds to the first element in
28      * {@link SchemaNodeIdentifier.Absolute#firstNodeIdentifier()}.
29      */
30     @Override
31     List<@NonNull SchemaTreeEffectiveStatement<?>> statementPath();
32
33     /**
34      * Return the {@link SchemaNodeIdentifier.Absolute} which resulted in this inference.
35      *
36      * @implSpec
37      *      Default implementation interprets {@link #statementPath()}'s arguments as the ordered source of
38      *      {@link SchemaNodeIdentifier.Absolute} steps.
39      *
40      * @return An absolute SchemaNodeIdentifier
41      */
42     default SchemaNodeIdentifier.Absolute toSchemaNodeIdentifier() {
43         return SchemaNodeIdentifier.Absolute.of(statementPath().stream()
44             .map(SchemaTreeEffectiveStatement::argument)
45             .collect(ImmutableList.toImmutableList()));
46     }
47 }