FrankWang | ea70de3 | 2018-05-08 15:41:25 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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.net.pi.runtime.data; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.Objects; |
| 21 | import org.onlab.util.ImmutableByteSequence; |
| 22 | import org.onosproject.net.pi.model.PiData; |
| 23 | |
| 24 | /** |
| 25 | * BitString entity in a protocol-independent pipeline. |
| 26 | */ |
| 27 | @Beta |
| 28 | public final class PiBitString implements PiData { |
| 29 | private final ImmutableByteSequence bitString; |
| 30 | |
| 31 | /** |
| 32 | * Creates a new protocol-independent bit string instance. |
| 33 | * |
| 34 | * @param bitString bitString |
| 35 | */ |
| 36 | private PiBitString(ImmutableByteSequence bitString) { |
| 37 | this.bitString = bitString; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Returns a new protocol-independent BitString. |
| 42 | * @param bitString bitString |
| 43 | * @return BitString |
| 44 | */ |
| 45 | public static PiBitString of(ImmutableByteSequence bitString) { |
| 46 | return new PiBitString(bitString); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Return protocol-independent bitString instance. |
| 51 | * |
| 52 | * @return bitString |
| 53 | */ |
| 54 | public ImmutableByteSequence bitString() { |
| 55 | return this.bitString; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public Type type() { |
| 60 | return Type.BITSTRING; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public boolean equals(Object o) { |
| 65 | if (this == o) { |
| 66 | return true; |
| 67 | } |
| 68 | if (o == null || getClass() != o.getClass()) { |
| 69 | return false; |
| 70 | } |
| 71 | PiBitString bitStr = (PiBitString) o; |
| 72 | return Objects.equal(bitString, bitStr.bitString); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public int hashCode() { |
| 77 | return Objects.hashCode(bitString); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public String toString() { |
| 82 | return bitString.toString(); |
| 83 | } |
| 84 | } |