blob: df702e97baa03cd2c28fea25fc577b7303a77206 [file] [log] [blame]
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05303 *
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
Bharat saraswald9822e92016-04-05 15:13:44 +053019import java.util.Objects;
20
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053021import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22import org.onosproject.yangutils.parser.Parsable;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053023import org.onosproject.yangutils.utils.YangConstructType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053024
25/*-
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/**
Bharat saraswald9822e92016-04-05 15:13:44 +053051 * Represents the ENUM data type information.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053052 */
Vidyashree Rama210c01d2016-05-20 16:29:25 +053053public class YangEnum implements YangCommonInfo, Parsable, Comparable<YangEnum> {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053054
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 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053076 * Value of ENUM.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053077 */
78 private int value;
79
80 /**
81 * Create a YANG ENUM.
82 */
83 public YangEnum() {
84
85 }
86
87 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053088 * Returns the named value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053089 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053090 * @return the named value
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053091 */
92 public String getNamedValue() {
93 return namedValue;
94 }
95
96 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053097 * Sets the named value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053098 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053099 * @param namedValue the named value to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530100 */
101 public void setNamedValue(String namedValue) {
102 this.namedValue = namedValue;
103 }
104
105 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530106 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530107 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530108 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530109 */
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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530116 * Sets the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530117 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530118 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530119 */
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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530126 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530127 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530128 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530129 */
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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530136 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530137 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530138 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530139 */
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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530146 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530147 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530148 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530149 */
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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530156 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530157 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530158 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530159 */
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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530166 * Returns the value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530167 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530168 * @return the value
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530169 */
170 public int getValue() {
171 return value;
172 }
173
174 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530175 * Sets the value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530176 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530177 * @param value the value to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530178 */
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
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530189 public YangConstructType getYangConstructType() {
190 return YangConstructType.ENUM_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530191 }
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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530211 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530212 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530213 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530214 */
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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530221 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530222 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530223 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530224 */
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 }
Vidyashree Rama210c01d2016-05-20 16:29:25 +0530229
230 @Override
231 public int compareTo(YangEnum otherEnum) {
232 if (this.namedValue.equals(otherEnum.getNamedValue())) {
233 return 0;
234 }
235 return new Integer(this.value).compareTo(otherEnum.getValue());
236 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530237}