blob: 4771aad4f602a5637a182d851e313d4fb1ca2bc8 [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
19import java.util.HashSet;
20import java.util.Set;
21
22import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23import org.onosproject.yangutils.parser.Parsable;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053024import org.onosproject.yangutils.utils.YangConstructType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053025
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/**
Bharat saraswald9822e92016-04-05 15:13:44 +053035 * Represents the bits data type information.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053036 */
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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053046 * Creates a YANG bits type object.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053047 */
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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053062 * Sets 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 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053071 * Adds bit info.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053072 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +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)) {
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053078 throw new DataModelException("YANG file error: Duplicate identifier detected, same as bit \""
79 + bitInfo.getBitName() + "\"");
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053080 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053081 }
82
83 /**
84 * Returns the type of the data.
85 *
86 * @return ParsedDataType returns BITS_DATA
87 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053088 @Override
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053089 public YangConstructType getYangConstructType() {
90 return YangConstructType.BITS_DATA;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053091 }
92
93 /**
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053094 * Returns the bits name.
95 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053096 * @return name of the bits
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +053097 */
98 public String getBitsName() {
99 return bitsName;
100 }
101
102 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530103 * Sets bits name.
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +0530104 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530105 * @param bitsName bit name to be set
Gaurav Agrawal0cfdeed2016-02-26 02:47:39 +0530106 */
107 public void setBitsName(String bitsName) {
108 this.bitsName = bitsName;
109 }
110
111 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530112 * Validates the data on entering the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530113 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530114 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530115 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530116 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530117 public void validateDataOnEntry() throws DataModelException {
118 // TODO auto-generated method stub, to be implemented by parser
119 }
120
121 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530122 * Validates the data on exiting the corresponding parse tree node.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530123 *
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +0530124 * @throws DataModelException a violation of data model rules
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530125 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530126 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530127 public void validateDataOnExit() throws DataModelException {
128 // TODO auto-generated method stub, to be implemented by parser
129 }
130}