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