blob: 1e1d3252b2b4ad77cb872c79e8a9c0fdd4720a9e [file] [log] [blame]
Bharat saraswal33dfa012016-05-17 19:59:16 +05301/*
2 * Copyright 2016-present 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
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053017package org.onosproject.yangutils.datamodel.utils.builtindatatype;
Bharat saraswal33dfa012016-05-17 19:59:16 +053018
Bharat saraswal96dfef02016-06-16 00:29:12 +053019import java.io.Serializable;
Bharat saraswal33dfa012016-05-17 19:59:16 +053020import java.util.Objects;
Bharat saraswal96dfef02016-06-16 00:29:12 +053021
Bharat saraswal33dfa012016-05-17 19:59:16 +053022import com.google.common.base.MoreObjects;
23
24/**
25 * Represents bits data type.
26 */
Bharat saraswal96dfef02016-06-16 00:29:12 +053027public class YangBits implements Serializable {
28
29 private static final long serialVersionUID = 8006201669L;
Bharat saraswal33dfa012016-05-17 19:59:16 +053030
31 private byte[] byteArray;
32
33 /**
34 * Creates an instance of YANG bits.
35 */
36 private YangBits() {
37 }
38
39 /**
40 * Creates an instance of YANG bits.
41 *
42 * @param bytes byte array
43 */
44 public YangBits(byte[] bytes) {
Bharat saraswal96dfef02016-06-16 00:29:12 +053045 byteArray = bytes;
Bharat saraswal33dfa012016-05-17 19:59:16 +053046 }
47
48 /**
49 * Returns object of YANG bits.
50 *
51 * @param bytes byte array
52 * @return object of YANG bits
53 */
54 public static YangBits of(byte[] bytes) {
55 return new YangBits(bytes);
56 }
57
58 /**
59 * Returns byte array.
60 *
61 * @return byte array
62 */
63 public byte[] byteArray() {
64 return byteArray;
65 }
66
67 @Override
68 public int hashCode() {
69 return Objects.hash(byteArray);
70 }
71
72 @Override
73 public boolean equals(Object obj) {
74 if (this == obj) {
75 return true;
76 }
77 if (obj instanceof YangBits) {
78 YangBits other = (YangBits) obj;
79 return Objects.equals(byteArray, other.byteArray);
80 }
81 return false;
82 }
83
84 @Override
85 public String toString() {
86 return MoreObjects.toStringHelper(getClass())
87 .omitNullValues()
88 .add("byteArray", byteArray)
89 .toString();
90 }
91
92 /**
93 * Returns the object of YANG bits fromString input String.
94 *
95 * @param valInString input String
96 * @return Object of YANG bits
97 */
98 public static YangBits fromString(String valInString) {
99 try {
100 byte[] tmpVal = valInString.getBytes();
101 return of(tmpVal);
102 } catch (Exception e) {
103 }
104 return null;
105 }
106
107}