Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.yangutils.datamodel; |
| 18 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 19 | import java.io.Serializable; |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 20 | import java.util.Objects; |
| 21 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
| 24 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 25 | |
| 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 saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 52 | * Represents the ENUM data type information. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 53 | */ |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 54 | public class YangEnum implements YangCommonInfo, Parsable, Comparable<YangEnum>, Serializable { |
| 55 | |
| 56 | private static final long serialVersionUID = 806201643L; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 57 | |
| 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 Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 79 | * Value of ENUM. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 80 | */ |
| 81 | private int value; |
| 82 | |
| 83 | /** |
| 84 | * Create a YANG ENUM. |
| 85 | */ |
| 86 | public YangEnum() { |
| 87 | |
| 88 | } |
| 89 | |
| 90 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 91 | * Returns the named value. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 92 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 93 | * @return the named value |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 94 | */ |
| 95 | public String getNamedValue() { |
| 96 | return namedValue; |
| 97 | } |
| 98 | |
| 99 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 100 | * Sets the named value. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 101 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 102 | * @param namedValue the named value to set |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 103 | */ |
| 104 | public void setNamedValue(String namedValue) { |
| 105 | this.namedValue = namedValue; |
| 106 | } |
| 107 | |
| 108 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 109 | * Returns the description. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 110 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 111 | * @return the description |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 112 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 113 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 114 | public String getDescription() { |
| 115 | return description; |
| 116 | } |
| 117 | |
| 118 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 119 | * Sets the description. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 120 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 121 | * @param description set the description |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 122 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 123 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 124 | public void setDescription(String description) { |
| 125 | this.description = description; |
| 126 | } |
| 127 | |
| 128 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 129 | * Returns the textual reference. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 130 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 131 | * @return the reference |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 132 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 133 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 134 | public String getReference() { |
| 135 | return reference; |
| 136 | } |
| 137 | |
| 138 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 139 | * Sets the textual reference. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 140 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 141 | * @param reference the reference to set |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 142 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 143 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 144 | public void setReference(String reference) { |
| 145 | this.reference = reference; |
| 146 | } |
| 147 | |
| 148 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 149 | * Returns the status. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 150 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 151 | * @return the status |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 152 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 153 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 154 | public YangStatusType getStatus() { |
| 155 | return status; |
| 156 | } |
| 157 | |
| 158 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 159 | * Sets the status. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 160 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 161 | * @param status the status to set |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 162 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 163 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 164 | public void setStatus(YangStatusType status) { |
| 165 | this.status = status; |
| 166 | } |
| 167 | |
| 168 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 169 | * Returns the value. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 170 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 171 | * @return the value |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 172 | */ |
| 173 | public int getValue() { |
| 174 | return value; |
| 175 | } |
| 176 | |
| 177 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 178 | * Sets the value. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 179 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 180 | * @param value the value to set |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 181 | */ |
| 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 S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 191 | @Override |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 192 | public YangConstructType getYangConstructType() { |
| 193 | return YangConstructType.ENUM_DATA; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 194 | } |
| 195 | |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 196 | @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 saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 203 | return Objects.equals(namedValue, other.namedValue); |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 204 | } |
| 205 | return false; |
| 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public int hashCode() { |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 210 | return Objects.hashCode(namedValue); |
Gaurav Agrawal | 9c512e0 | 2016-02-25 04:37:05 +0530 | [diff] [blame] | 211 | } |
| 212 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 213 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 214 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 215 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 216 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 217 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 218 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 219 | public void validateDataOnEntry() throws DataModelException { |
| 220 | // TODO auto-generated method stub, to be implemented by parser |
| 221 | } |
| 222 | |
| 223 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 224 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 225 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 226 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 227 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 228 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 229 | public void validateDataOnExit() throws DataModelException { |
| 230 | // TODO auto-generated method stub, to be implemented by parser |
| 231 | } |
Vidyashree Rama | 210c01d | 2016-05-20 16:29:25 +0530 | [diff] [blame] | 232 | |
| 233 | @Override |
| 234 | public int compareTo(YangEnum otherEnum) { |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 235 | if (namedValue.equals(otherEnum.getNamedValue())) { |
Vidyashree Rama | 210c01d | 2016-05-20 16:29:25 +0530 | [diff] [blame] | 236 | return 0; |
| 237 | } |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 238 | return new Integer(value).compareTo(otherEnum.getValue()); |
Vidyashree Rama | 210c01d | 2016-05-20 16:29:25 +0530 | [diff] [blame] | 239 | } |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 240 | } |