Rename StatementSource to StatementOrigin
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / source / ImplicitSubstatement.java
1 /*
2  * Copyright (c) 2017 Cisco Systems, Inc. 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.parser.spi.source;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import org.opendaylight.yangtools.yang.model.api.meta.StatementOrigin;
14
15 /**
16  * An implicit sub-statement, which is implied to be always present in its parent, even if it does not appear
17  * in model source.
18  *
19  * @author Robert Varga
20  */
21 @Beta
22 public final class ImplicitSubstatement implements StatementSourceReference {
23
24     private final StatementSourceReference parentRef;
25
26     private ImplicitSubstatement(final StatementSourceReference parentRef) {
27         this.parentRef = requireNonNull(parentRef);
28     }
29
30     /**
31      * Create a new {@link ImplicitSubstatement}.
32      *
33      * @param parentRef Parent source reference
34      * @return A new reference
35      * @throws NullPointerException if parentRef is null
36      */
37     public static ImplicitSubstatement of(final StatementSourceReference parentRef) {
38         return new ImplicitSubstatement(parentRef);
39     }
40
41     @Override
42     public StatementOrigin statementOrigin() {
43         return StatementOrigin.CONTEXT;
44     }
45
46     @Override
47     public int hashCode() {
48         return parentRef.hashCode();
49     }
50
51     @Override
52     public boolean equals(final Object obj) {
53         return obj instanceof ImplicitSubstatement && parentRef.equals(((ImplicitSubstatement) obj).parentRef);
54     }
55
56     @Override
57     public String toString() {
58         return parentRef.toString();
59     }
60 }