Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 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 | |
| 19 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 20 | import org.onosproject.yangutils.parser.Parsable; |
| 21 | import org.onosproject.yangutils.parser.ParsableDataType; |
| 22 | |
Gaurav Agrawal | 480a47d | 2016-02-26 02:47:39 +0530 | [diff] [blame^] | 23 | import java.util.Objects; |
| 24 | |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 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 | /** |
| 47 | * Maintains the bit data type information. |
| 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 | * |
| 86 | * @return the bit name. |
| 87 | */ |
| 88 | public String getBitName() { |
| 89 | return bitName; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Set the bit name. |
| 94 | * |
| 95 | * @param bitName the bit name to set. |
| 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 | * |
| 104 | * @return the description. |
| 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 | /** |
| 112 | * Set the description. |
| 113 | * |
| 114 | * @param description set the description. |
| 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 | * |
| 124 | * @return the reference. |
| 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 | /** |
| 132 | * Set the textual reference. |
| 133 | * |
| 134 | * @param reference the reference to set. |
| 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 | * |
| 144 | * @return the status. |
| 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 | /** |
| 152 | * Set the status. |
| 153 | * |
| 154 | * @param status the status to set. |
| 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 | /** |
| 171 | * Set the bit position. |
| 172 | * |
| 173 | * @param position the position to set. |
| 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 |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 185 | public ParsableDataType getParsableDataType() { |
| 186 | return ParsableDataType.BIT_DATA; |
| 187 | } |
| 188 | |
Gaurav Agrawal | 480a47d | 2016-02-26 02:47:39 +0530 | [diff] [blame^] | 189 | @Override |
| 190 | public boolean equals(Object obj) { |
| 191 | if (this == obj) { |
| 192 | return true; |
| 193 | } |
| 194 | if (obj instanceof YangBit) { |
| 195 | final YangBit other = (YangBit) obj; |
| 196 | return Objects.equals(this.bitName, other.bitName); |
| 197 | } |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public int hashCode() { |
| 203 | return Objects.hashCode(this.bitName); |
| 204 | } |
| 205 | |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 206 | /** |
| 207 | * Validate the data on entering the corresponding parse tree node. |
| 208 | * |
| 209 | * @throws DataModelException a violation of data model rules. |
| 210 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 211 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 212 | public void validateDataOnEntry() throws DataModelException { |
| 213 | // TODO auto-generated method stub, to be implemented by parser |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Validate the data on exiting the corresponding parse tree node. |
| 218 | * |
| 219 | * @throws DataModelException a violation of data model rules. |
| 220 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 221 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 222 | public void validateDataOnExit() throws DataModelException { |
| 223 | // TODO auto-generated method stub, to be implemented by parser |
| 224 | } |
| 225 | } |