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 "bit" statement, which is a sub-statement to the "type" statement, |
| 28 | * MUST be present if the type is "bits". It is repeatedly used to |
| 29 | * specify each assigned named bit of a bits type. It takes as an |
| 30 | * argument a string that is the assigned name of the bit. It is |
| 31 | * followed by a block of sub-statements that holds detailed bit |
| 32 | * information. |
| 33 | * All assigned names in a bits type MUST be unique. |
| 34 | * |
| 35 | * The bit's sub-statements |
| 36 | * |
| 37 | * +--------------+---------+-------------+------------------+ |
| 38 | * | substatement | section | cardinality |data model mapping| |
| 39 | * +--------------+---------+-------------+------------------+ |
| 40 | * | description | 7.19.3 | 0..1 | - string | |
| 41 | * | reference | 7.19.4 | 0..1 | - string | |
| 42 | * | status | 7.19.2 | 0..1 | - YangStatus | |
| 43 | * | position | 9.7.4.2 | 0..1 | - int | |
| 44 | * +--------------+---------+-------------+------------------+ |
| 45 | */ |
| 46 | |
| 47 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 48 | * Represents the bit data type information. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 49 | */ |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 50 | public class YangBit implements YangCommonInfo, Parsable, Serializable { |
| 51 | |
| 52 | private static final long serialVersionUID = 806201640L; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Name of the bit. |
| 56 | */ |
| 57 | private String bitName; |
| 58 | |
| 59 | /** |
| 60 | * Description of the bit field. |
| 61 | */ |
| 62 | private String description; |
| 63 | |
| 64 | /** |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 65 | * Reference info of the bit field. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 66 | */ |
| 67 | private String reference; |
| 68 | |
| 69 | /** |
| 70 | * Status of the bit field. |
| 71 | */ |
| 72 | private YangStatusType status; |
| 73 | |
| 74 | /** |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 75 | * Position of the bit whose name bit is described. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 76 | */ |
| 77 | private int position; |
| 78 | |
| 79 | /** |
| 80 | * Create a YANG bit type object. |
| 81 | */ |
| 82 | public YangBit() { |
| 83 | |
| 84 | } |
| 85 | |
| 86 | /** |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 87 | * Returns bit name. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 88 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 89 | * @return the bit name |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 90 | */ |
| 91 | public String getBitName() { |
| 92 | return bitName; |
| 93 | } |
| 94 | |
| 95 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 96 | * Sets the bit name. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 97 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 98 | * @param bitName the bit name to set |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 99 | */ |
| 100 | public void setBitName(String bitName) { |
| 101 | this.bitName = bitName; |
| 102 | } |
| 103 | |
| 104 | /** |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 105 | * Returns description. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 106 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 107 | * @return the description |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 108 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 109 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 110 | public String getDescription() { |
| 111 | return description; |
| 112 | } |
| 113 | |
| 114 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 115 | * Sets the description. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 116 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 117 | * @param description set the description |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 118 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 119 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 120 | public void setDescription(String description) { |
| 121 | this.description = description; |
| 122 | } |
| 123 | |
| 124 | /** |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 125 | * Returns textual reference. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 126 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 127 | * @return the reference |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 128 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 129 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 130 | public String getReference() { |
| 131 | return reference; |
| 132 | } |
| 133 | |
| 134 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 135 | * Sets the textual reference. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 136 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 137 | * @param reference the reference to set |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 138 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 139 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 140 | public void setReference(String reference) { |
| 141 | this.reference = reference; |
| 142 | } |
| 143 | |
| 144 | /** |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 145 | * Returns status. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 146 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 147 | * @return the status |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 148 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 149 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 150 | public YangStatusType getStatus() { |
| 151 | return status; |
| 152 | } |
| 153 | |
| 154 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 155 | * Sets the status. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 156 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 157 | * @param status the status to set |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 158 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 159 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 160 | public void setStatus(YangStatusType status) { |
| 161 | this.status = status; |
| 162 | } |
| 163 | |
| 164 | /** |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 165 | * Returns bit position. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 166 | * |
| 167 | * @return the position |
| 168 | */ |
| 169 | public int getPosition() { |
| 170 | return position; |
| 171 | } |
| 172 | |
| 173 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 174 | * Sets the bit position. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 175 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 176 | * @param position the position to set |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 177 | */ |
| 178 | public void setPosition(int position) { |
| 179 | this.position = position; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Returns the type of the data. |
| 184 | * |
| 185 | * @return ParsedDataType returns BIT_DATA |
| 186 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 187 | @Override |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 188 | public YangConstructType getYangConstructType() { |
| 189 | return YangConstructType.BIT_DATA; |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 190 | } |
| 191 | |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 192 | @Override |
| 193 | public boolean equals(Object obj) { |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 194 | |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 195 | if (this == obj) { |
| 196 | return true; |
| 197 | } |
| 198 | if (obj instanceof YangBit) { |
| 199 | final YangBit other = (YangBit) obj; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 200 | return Objects.equals(bitName, other.bitName); |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 201 | } |
| 202 | return false; |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public int hashCode() { |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 207 | return Objects.hashCode(bitName); |
Gaurav Agrawal | 0cfdeed | 2016-02-26 02:47:39 +0530 | [diff] [blame] | 208 | } |
| 209 | |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 210 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 211 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 212 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 213 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 214 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 215 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 216 | public void validateDataOnEntry() throws DataModelException { |
| 217 | // TODO auto-generated method stub, to be implemented by parser |
| 218 | } |
| 219 | |
| 220 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 221 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 222 | * |
Gaurav Agrawal | 8e8770a | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 223 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 224 | */ |
Vinod Kumar S | 0c330cd | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 225 | @Override |
Vinod Kumar S | 2ff139c | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 226 | public void validateDataOnExit() throws DataModelException { |
| 227 | // TODO auto-generated method stub, to be implemented by parser |
| 228 | } |
| 229 | } |