blob: 04ea232ae43416f6281aca04d05ce338dbedad2d [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 saraswal96dfef02016-06-16 00:29:12 +053019import java.io.Serializable;
Bharat saraswald9822e92016-04-05 15:13:44 +053020import java.util.Objects;
21
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053022import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053023import org.onosproject.yangutils.datamodel.utils.Parsable;
24import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053025
26/*-
27 * The "ENUM" statement, which is a sub-statement to the "type"
28 * statement, MUST be present if the type is "enumeration". It is
29 * repeatedly used to specify each assigned name of an enumeration type.
30 * It takes as an argument a string which is the assigned name. The
31 * string MUST NOT be empty and MUST NOT have any leading or trailing
32 * whitespace characters. The use of Unicode control codes SHOULD be
33 * avoided.
34 *
35 * The statement is optionally followed by a block of sub-statements that
36 * holds detailed ENUM information.
37 * All assigned names in an enumeration MUST be unique.
38 *
39 * The ENUM's sub-statements
40 *
41 * +--------------+---------+-------------+------------------+
42 * | substatement | section | cardinality |data model mapping|
43 * +--------------+---------+-------------+------------------+
44 * | description | 7.19.3 | 0..1 | - string |
45 * | reference | 7.19.4 | 0..1 | - string |
46 * | status | 7.19.2 | 0..1 | - YangStatus |
47 * | value | 9.6.4.2 | 0..1 | - int |
48 * +--------------+---------+-------------+------------------+
49 */
50
51/**
Bharat saraswald9822e92016-04-05 15:13:44 +053052 * Represents the ENUM data type information.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053053 */
Bharat saraswal96dfef02016-06-16 00:29:12 +053054public class YangEnum implements YangCommonInfo, Parsable, Comparable<YangEnum>, Serializable {
55
56 private static final long serialVersionUID = 806201643L;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053057
58 /**
59 * Named value for the ENUM.
60 */
61 private String namedValue;
62
63 /**
64 * Description of the ENUM value.
65 */
66 private String description;
67
68 /**
69 * Reference info of the ENUM value.
70 */
71 private String reference;
72
73 /**
74 * Status of the ENUM value.
75 */
76 private YangStatusType status;
77
78 /**
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053079 * Value of ENUM.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053080 */
81 private int value;
82
83 /**
84 * Create a YANG ENUM.
85 */
86 public YangEnum() {
87
88 }
89
90 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053091 * Returns the named value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053092 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053093 * @return the named value
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053094 */
95 public String getNamedValue() {
96 return namedValue;
97 }
98
99 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530100 * Sets the named value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530101 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530102 * @param namedValue the named value to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530103 */
104 public void setNamedValue(String namedValue) {
105 this.namedValue = namedValue;
106 }
107
108 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530109 * Returns the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530110 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530111 * @return the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530112 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530113 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530114 public String getDescription() {
115 return description;
116 }
117
118 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530119 * Sets the description.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530120 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530121 * @param description set the description
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530122 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530123 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530124 public void setDescription(String description) {
125 this.description = description;
126 }
127
128 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530129 * Returns the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530130 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530131 * @return the reference
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530132 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530133 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530134 public String getReference() {
135 return reference;
136 }
137
138 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530139 * Sets the textual reference.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530140 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530141 * @param reference the reference to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530142 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530143 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530144 public void setReference(String reference) {
145 this.reference = reference;
146 }
147
148 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530149 * Returns the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530150 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530151 * @return the status
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530152 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530153 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530154 public YangStatusType getStatus() {
155 return status;
156 }
157
158 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530159 * Sets the status.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530160 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530161 * @param status the status to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530162 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530163 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530164 public void setStatus(YangStatusType status) {
165 this.status = status;
166 }
167
168 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530169 * Returns the value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530170 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530171 * @return the value
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530172 */
173 public int getValue() {
174 return value;
175 }
176
177 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530178 * Sets the value.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530179 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530180 * @param value the value to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530181 */
182 public void setValue(int value) {
183 this.value = value;
184 }
185
186 /**
187 * Returns the type of the data.
188 *
189 * @return ParsedDataType returns ENUM_DATA
190 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530191 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530192 public YangConstructType getYangConstructType() {
193 return YangConstructType.ENUM_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530194 }
195
Gaurav Agrawal9c512e02016-02-25 04:37:05 +0530196 @Override
197 public boolean equals(Object obj) {
198 if (this == obj) {
199 return true;
200 }
201 if (obj instanceof YangEnum) {
202 final YangEnum other = (YangEnum) obj;
Bharat saraswal96dfef02016-06-16 00:29:12 +0530203 return Objects.equals(namedValue, other.namedValue);
Gaurav Agrawal9c512e02016-02-25 04:37:05 +0530204 }
205 return false;
206 }
207
208 @Override
209 public int hashCode() {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530210 return Objects.hashCode(namedValue);
Gaurav Agrawal9c512e02016-02-25 04:37:05 +0530211 }
212
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530213 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530214 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530215 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530216 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530217 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530218 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530219 public void validateDataOnEntry() throws DataModelException {
220 // TODO auto-generated method stub, to be implemented by parser
221 }
222
223 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530224 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530225 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530226 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530227 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530228 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530229 public void validateDataOnExit() throws DataModelException {
230 // TODO auto-generated method stub, to be implemented by parser
231 }
Vidyashree Rama210c01d2016-05-20 16:29:25 +0530232
233 @Override
234 public int compareTo(YangEnum otherEnum) {
Bharat saraswal96dfef02016-06-16 00:29:12 +0530235 if (namedValue.equals(otherEnum.getNamedValue())) {
Vidyashree Rama210c01d2016-05-20 16:29:25 +0530236 return 0;
237 }
Bharat saraswal96dfef02016-06-16 00:29:12 +0530238 return new Integer(value).compareTo(otherEnum.getValue());
Vidyashree Rama210c01d2016-05-20 16:29:25 +0530239 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530240}