Populate data/ hierarchy
[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 AbstractEffectiveModelContextProvider} and {@link EffectiveStatementInference}s.
23  *
24  * @param <T> constituent {@link EffectiveStatement} type
25  */
26 @Beta
27 public abstract class AbstractEffectiveStatementInference<T extends EffectiveStatement<?, ?>>
28         extends AbstractEffectiveModelContextProvider implements EffectiveStatementInference {
29     protected AbstractEffectiveStatementInference(final @NonNull EffectiveModelContext modelContext) {
30         super(modelContext);
31     }
32
33     @Override
34     public abstract List<T> statementPath();
35
36     /**
37      * A simple capture of an {@link AbstractEffectiveStatementInference} and a list of {@link EffectiveStatement}s. No
38      * further guarantees are made.
39      *
40      * @param <T> constituent {@link EffectiveStatement} type
41      */
42     @Beta
43     public abstract static class WithPath<T extends EffectiveStatement<?, ?>>
44             extends AbstractEffectiveStatementInference<T> {
45         private final @NonNull List<T> path;
46
47         protected WithPath(final @NonNull EffectiveModelContext modelContext, final @NonNull ImmutableList<T> path) {
48             super(modelContext);
49             this.path = requireNonNull(path);
50         }
51
52         protected WithPath(final @NonNull EffectiveModelContext modelContext, final @NonNull List<? extends T> path) {
53             super(modelContext);
54             this.path = ImmutableList.copyOf(path);
55         }
56
57         @Override
58         public final List<T> statementPath() {
59             return path;
60         }
61
62         @Override
63         protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
64             return super.addToStringAttributes(helper).add("path", path);
65         }
66     }
67 }