Add SchemaTreeInference
[yangtools.git] / yang / yang-model-spi / src / main / java / org / opendaylight / yangtools / yang / model / spi / AbstractEffectiveStatementInference.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.spi;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.MoreObjects.ToStringHelper;
14 import com.google.common.collect.ImmutableList;
15 import java.util.List;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.model.api.EffectiveStatementInference;
19 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
20
21 /**
22  * A simple capture of an {@link EffectiveModelContext} and a list of {@link EffectiveStatement}s. No further guarantees
23  * are made.
24  *
25  * @param T constituent {@link EffectiveStatement} type
26  */
27 @Beta
28 public abstract class AbstractEffectiveStatementInference<T extends EffectiveStatement<?, ?>>
29         extends AbstractEffectiveModelContextProvider implements EffectiveStatementInference {
30     private final @NonNull List<T> path;
31
32     protected AbstractEffectiveStatementInference(final @NonNull EffectiveModelContext modelContext,
33             final @NonNull ImmutableList<T> path) {
34         super(modelContext);
35         this.path = requireNonNull(path);
36     }
37
38     protected AbstractEffectiveStatementInference(final @NonNull EffectiveModelContext modelContext,
39             final @NonNull List<? extends T> path) {
40         super(modelContext);
41         this.path = ImmutableList.copyOf(path);
42     }
43
44     @Override
45     public final List<T> statementPath() {
46         return path;
47     }
48
49     @Override
50     protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
51         return super.addToStringAttributes(helper).add("statements", path);
52     }
53 }