afe2a5865484ac3052f9efacf803e8ab4e77c767
[smo/teiv.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2024 Ericsson
4  *  Modifications Copyright (C) 2024 OpenInfra Foundation Europe
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21 package org.oran.smo.yangtools.parser.model.statements;
22
23 import java.util.Objects;
24
25 import org.oran.smo.yangtools.parser.model.statements.yang.CY;
26
27 /**
28  * Holds information about the name of a statement, and the module where the statement has
29  * been defined.
30  *
31  * @author Mark Hollmann
32  */
33 public class StatementModuleAndName {
34
35     private final String moduleName;
36     private final String statementName;
37     private final boolean isYangCoreStatement;
38
39     /**
40      * Creates a new SMAN. The module name is the name of the module defining the statement.
41      */
42     public StatementModuleAndName(final String moduleName, final String statementName) {
43         this.moduleName = Objects.requireNonNull(moduleName);
44         this.statementName = Objects.requireNonNull(statementName);
45         this.isYangCoreStatement = CY.YANG_CORE_MODULE_NAME.equals(moduleName);
46     }
47
48     /**
49      * Returns the module in which the statement has been defined. If the statement is part of
50      * the core YANG language, the constant {@link CY.YANG_CORE_MODULE_NAME} will be returned.
51      */
52     public String getModuleName() {
53         return moduleName;
54     }
55
56     /**
57      * Returns whether this statement is part of the YANG core language.
58      */
59     public boolean isYangCoreStatement() {
60         return isYangCoreStatement;
61     }
62
63     /**
64      * Returns whether this statement is an extension statement.
65      */
66     public boolean isExtensionStatement() {
67         return !isYangCoreStatement;
68     }
69
70     /**
71      * Returns the statement name. Note that different modules may define
72      * extensions having the same (statement-) name.
73      */
74     public String getStatementName() {
75         return statementName;
76     }
77
78     @Override
79     public int hashCode() {
80         return statementName.hashCode();
81     }
82
83     @Override
84     public String toString() {
85         return isYangCoreStatement() ? statementName : moduleName + ":" + statementName;
86     }
87
88     @Override
89     public boolean equals(final Object obj) {
90
91         if (this == obj) {
92             return true;
93         }
94
95         if (!(obj instanceof StatementModuleAndName)) {
96             return false;
97         }
98
99         final StatementModuleAndName other = (StatementModuleAndName) obj;
100
101         return this.statementName.equals(other.statementName) && this.moduleName.equals(other.moduleName);
102     }
103 }