blob: a93379b143a22deee027ac2409bc04527be19872 [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
19import java.util.Objects;
Bharat saraswal33dfa012016-05-17 19:59:16 +053020import com.google.common.base.MoreObjects;
21
22/**
23 * Represents binary data type.
24 */
25public final class YangBinary {
26
27 private byte[] byteArray;
28
29 /**
30 * Creates an instance of YANG binary.
31 */
32 private YangBinary() {
33 }
34
35 /**
36 * Creates an instance of YANG binary.
37 *
38 * @param bytes byte array
39 */
40 public YangBinary(byte[] bytes) {
41 this.byteArray = bytes;
42 }
43
44 /**
45 * Returns object of YANG binary.
46 *
47 * @param bytes byte array
48 * @return object of YANG binary
49 */
50 public static YangBinary of(byte[] bytes) {
51 return new YangBinary(bytes);
52 }
53
54 /**
55 * Returns byte array.
56 *
57 * @return byte array
58 */
59 public byte[] byteArray() {
60 return byteArray;
61 }
62
63 @Override
64 public int hashCode() {
65 return Objects.hash(byteArray);
66 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73 if (obj instanceof YangBinary) {
74 YangBinary other = (YangBinary) obj;
75 return Objects.equals(byteArray, other.byteArray);
76 }
77 return false;
78 }
79
80 @Override
81 public String toString() {
82 return MoreObjects.toStringHelper(getClass())
83 .omitNullValues()
84 .add("byteArray", byteArray)
85 .toString();
86 }
87
88 /**
89 * Returns the object of YANG binary fromString input String.
90 *
91 * @param valInString input String
92 * @return Object of YANG binary
93 */
94 public static YangBinary fromString(String valInString) {
95 try {
96 byte[] tmpVal = valInString.getBytes();
97 return of(tmpVal);
98 } catch (Exception e) {
99 }
100 return null;
101 }
102
103}