Populate model/ hierarchy
[yangtools.git] / model / yang-model-spi / src / main / java / org / opendaylight / yangtools / yang / model / spi / meta / AbstractRefStatement.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.meta;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Optional;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.concepts.Delegator;
15 import org.opendaylight.yangtools.yang.common.Empty;
16 import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18
19 /**
20  * Abstract base class for {@link DeclaredStatement} implementations which decorate a statement with a
21  * {@link DeclarationReference}.
22  *
23  * @param <A> Argument type ({@link Empty} if statement does not have argument.)
24  * @param <D> Class representing declared version of this statement.
25  */
26 public abstract class AbstractRefStatement<A, D extends DeclaredStatement<A>>
27         extends ForwardingDeclaredStatement<A, D> implements Delegator<D> {
28     private final @NonNull DeclarationReference ref;
29     private final @NonNull D delegate;
30
31     protected AbstractRefStatement(final D delegate, final DeclarationReference ref) {
32         this.delegate = requireNonNull(delegate);
33         this.ref = requireNonNull(ref);
34     }
35
36     @Override
37     public final Optional<DeclarationReference> declarationReference() {
38         return Optional.of(ref);
39     }
40
41     @Override
42     public final D getDelegate() {
43         return delegate;
44     }
45
46     @Override
47     protected final D delegate() {
48         return delegate;
49     }
50 }