blob: 84076ddf9fa64e0fae7dbf4a9fc06210561065fd [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;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053020import java.util.HashSet;
21import java.util.Set;
22
23import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
Bharat saraswal96dfef02016-06-16 00:29:12 +053024import org.onosproject.yangutils.datamodel.utils.Parsable;
25import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053026
27/*
28 * Reference RFC 6020.
29 *
30 * The bits built-in type represents a bit set. That is, a bits value
31 * is a set of flags identified by small integer position numbers
32 * starting at 0. Each bit number has an assigned name.
33 */
34
35/**
Bharat saraswald9822e92016-04-05 15:13:44 +053036 * Represents the bits data type information.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053037 */
Bharat saraswal96dfef02016-06-16 00:29:12 +053038public class YangBits implements Parsable, Serializable {
39
40 private static final long serialVersionUID = 806201641L;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053041
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053042 // Bits information set.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053043 private Set<YangBit> bitSet;
44
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053045 // BITS name.
46 private String bitsName;
47
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053048 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053049 * Creates a YANG bits type object.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053050 */
51 public YangBits() {
52 setBitSet(new HashSet<YangBit>());
53 }
54
55 /**
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053056 * Returns the bit set.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053057 *
58 * @return the bit set
59 */
60 public Set<YangBit> getBitSet() {
61 return bitSet;
62 }
63
64 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053065 * Sets the bit set.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053066 *
67 * @param bitSet the bit set
68 */
69 private void setBitSet(Set<YangBit> bitSet) {
70 this.bitSet = bitSet;
71 }
72
73 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053074 * Adds bit info.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053075 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053076 * @param bitInfo the bit information to be added
77 * @throws DataModelException due to violation in data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053078 */
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053079 public void addBitInfo(YangBit bitInfo) throws DataModelException {
80 if (!getBitSet().add(bitInfo)) {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053081 throw new DataModelException("YANG file error: Duplicate identifier detected, same as bit \""
82 + bitInfo.getBitName() + "\"");
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053083 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053084 }
85
86 /**
87 * Returns the type of the data.
88 *
89 * @return ParsedDataType returns BITS_DATA
90 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053091 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053092 public YangConstructType getYangConstructType() {
93 return YangConstructType.BITS_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053094 }
95
96 /**
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053097 * Returns the bits name.
98 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053099 * @return name of the bits
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +0530100 */
101 public String getBitsName() {
102 return bitsName;
103 }
104
105 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530106 * Sets bits name.
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +0530107 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530108 * @param bitsName bit name to be set
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +0530109 */
110 public void setBitsName(String bitsName) {
111 this.bitsName = bitsName;
112 }
113
114 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530115 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530116 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530117 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530118 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530119 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530120 public void validateDataOnEntry() throws DataModelException {
121 // TODO auto-generated method stub, to be implemented by parser
122 }
123
124 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530125 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530126 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530127 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530128 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530129 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530130 public void validateDataOnExit() throws DataModelException {
131 // TODO auto-generated method stub, to be implemented by parser
132 }
133}