blob: 76ab0f3b22b99cb2c70e8554344dda1faa454d95 [file] [log] [blame]
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05301/*
2 * Copyright 2016 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.yangutils.datamodel;
18
19import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20import org.onosproject.yangutils.parser.Parsable;
21import org.onosproject.yangutils.parser.ParsableDataType;
22
Gaurav Agrawal9c512e02016-02-25 04:37:05 +053023import java.util.Objects;
24
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053025/*-
26 * The "ENUM" statement, which is a sub-statement to the "type"
27 * statement, MUST be present if the type is "enumeration". It is
28 * repeatedly used to specify each assigned name of an enumeration type.
29 * It takes as an argument a string which is the assigned name. The
30 * string MUST NOT be empty and MUST NOT have any leading or trailing
31 * whitespace characters. The use of Unicode control codes SHOULD be
32 * avoided.
33 *
34 * The statement is optionally followed by a block of sub-statements that
35 * holds detailed ENUM information.
36 * All assigned names in an enumeration MUST be unique.
37 *
38 * The ENUM's sub-statements
39 *
40 * +--------------+---------+-------------+------------------+
41 * | substatement | section | cardinality |data model mapping|
42 * +--------------+---------+-------------+------------------+
43 * | description | 7.19.3 | 0..1 | - string |
44 * | reference | 7.19.4 | 0..1 | - string |
45 * | status | 7.19.2 | 0..1 | - YangStatus |
46 * | value | 9.6.4.2 | 0..1 | - int |
47 * +--------------+---------+-------------+------------------+
48 */
49
50/**
51 * Maintains the ENUM data type information.
52 */
53public class YangEnum implements YangCommonInfo, Parsable {
54
55 /**
56 * Named value for the ENUM.
57 */
58 private String namedValue;
59
60 /**
61 * Description of the ENUM value.
62 */
63 private String description;
64
65 /**
66 * Reference info of the ENUM value.
67 */
68 private String reference;
69
70 /**
71 * Status of the ENUM value.
72 */
73 private YangStatusType status;
74
75 /**
76 * value of ENUM.
77 */
78 private int value;
79
80 /**
81 * Create a YANG ENUM.
82 */
83 public YangEnum() {
84
85 }
86
87 /**
88 * Get the named value.
89 *
90 * @return the named value.
91 */
92 public String getNamedValue() {
93 return namedValue;
94 }
95
96 /**
97 * Set the named value.
98 *
99 * @param namedValue the named value to set.
100 */
101 public void setNamedValue(String namedValue) {
102 this.namedValue = namedValue;
103 }
104
105 /**
106 * Get the description.
107 *
108 * @return the description.
109 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530110 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530111 public String getDescription() {
112 return description;
113 }
114
115 /**
116 * Set the description.
117 *
118 * @param description set the description.
119 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530120 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530121 public void setDescription(String description) {
122 this.description = description;
123 }
124
125 /**
126 * Get the textual reference.
127 *
128 * @return the reference.
129 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530130 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530131 public String getReference() {
132 return reference;
133 }
134
135 /**
136 * Set the textual reference.
137 *
138 * @param reference the reference to set.
139 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530140 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530141 public void setReference(String reference) {
142 this.reference = reference;
143 }
144
145 /**
146 * Get the status.
147 *
148 * @return the status.
149 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530150 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530151 public YangStatusType getStatus() {
152 return status;
153 }
154
155 /**
156 * Set the status.
157 *
158 * @param status the status to set.
159 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530160 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530161 public void setStatus(YangStatusType status) {
162 this.status = status;
163 }
164
165 /**
166 * Get the value.
167 *
168 * @return the value.
169 */
170 public int getValue() {
171 return value;
172 }
173
174 /**
175 * Set the value.
176 *
177 * @param value the value to set.
178 */
179 public void setValue(int value) {
180 this.value = value;
181 }
182
183 /**
184 * Returns the type of the data.
185 *
186 * @return ParsedDataType returns ENUM_DATA
187 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530188 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530189 public ParsableDataType getParsableDataType() {
190 return ParsableDataType.ENUM_DATA;
191 }
192
Gaurav Agrawal9c512e02016-02-25 04:37:05 +0530193 @Override
194 public boolean equals(Object obj) {
195 if (this == obj) {
196 return true;
197 }
198 if (obj instanceof YangEnum) {
199 final YangEnum other = (YangEnum) obj;
200 return Objects.equals(this.namedValue, other.namedValue);
201 }
202 return false;
203 }
204
205 @Override
206 public int hashCode() {
207 return Objects.hashCode(this.namedValue);
208 }
209
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530210 /**
211 * Validate the data on entering the corresponding parse tree node.
212 *
213 * @throws DataModelException a violation of data model rules.
214 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530215 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530216 public void validateDataOnEntry() throws DataModelException {
217 // TODO auto-generated method stub, to be implemented by parser
218 }
219
220 /**
221 * Validate the data on exiting the corresponding parse tree node.
222 *
223 * @throws DataModelException a violation of data model rules.
224 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530225 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530226 public void validateDataOnExit() throws DataModelException {
227 // TODO auto-generated method stub, to be implemented by parser
228 }
229}