blob: 54898a4cf08fc2cc758677d1ec96c8bbf892c6ad [file] [log] [blame]
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05301/*
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
17package org.onosproject.yangutils.datamodel;
18
19import java.util.HashSet;
20import java.util.Set;
21
22import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23import org.onosproject.yangutils.parser.Parsable;
24import org.onosproject.yangutils.parser.ParsableDataType;
25
26/*
27 * Reference RFC 6020.
28 *
29 * The bits built-in type represents a bit set. That is, a bits value
30 * is a set of flags identified by small integer position numbers
31 * starting at 0. Each bit number has an assigned name.
32 */
33
34/**
35 * Maintains the bits data type information.
36 */
37public class YangBits implements Parsable {
38
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053039 // Bits information set.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053040 private Set<YangBit> bitSet;
41
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053042 // BITS name.
43 private String bitsName;
44
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053045 /**
46 * Create a YANG bits type object.
47 */
48 public YangBits() {
49 setBitSet(new HashSet<YangBit>());
50 }
51
52 /**
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053053 * Returns the bit set.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053054 *
55 * @return the bit set
56 */
57 public Set<YangBit> getBitSet() {
58 return bitSet;
59 }
60
61 /**
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053062 * Set the bit set.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053063 *
64 * @param bitSet the bit set
65 */
66 private void setBitSet(Set<YangBit> bitSet) {
67 this.bitSet = bitSet;
68 }
69
70 /**
71 * Add bit info.
72 *
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053073 * @param bitInfo the bit information to be added.
74 * @throws DataModelException due to violation in data model rules.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053075 */
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053076 public void addBitInfo(YangBit bitInfo) throws DataModelException {
77 if (!getBitSet().add(bitInfo)) {
78 throw new DataModelException("YANG Bit already exists");
79 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053080 }
81
82 /**
83 * Returns the type of the data.
84 *
85 * @return ParsedDataType returns BITS_DATA
86 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053087 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053088 public ParsableDataType getParsableDataType() {
89 return ParsableDataType.BITS_DATA;
90 }
91
92 /**
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053093 * Returns the bits name.
94 *
95 * @return name of the bits.
96 */
97 public String getBitsName() {
98 return bitsName;
99 }
100
101 /**
102 * Set bits name.
103 *
104 * @param bitsName bit name to be set.
105 */
106 public void setBitsName(String bitsName) {
107 this.bitsName = bitsName;
108 }
109
110 /**
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530111 * Validate the data on entering the corresponding parse tree node.
112 *
113 * @throws DataModelException a violation of data model rules.
114 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530115 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530116 public void validateDataOnEntry() throws DataModelException {
117 // TODO auto-generated method stub, to be implemented by parser
118 }
119
120 /**
121 * Validate the data on exiting the corresponding parse tree node.
122 *
123 * @throws DataModelException a violation of data model rules.
124 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530125 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530126 public void validateDataOnExit() throws DataModelException {
127 // TODO auto-generated method stub, to be implemented by parser
128 }
129}