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