Shashikanth VH | 47c2da1 | 2016-02-04 18:58:15 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Shashikanth VH | 47c2da1 | 2016-02-04 18:58:15 +0530 | [diff] [blame] | 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.bgpio.types; |
| 18 | |
| 19 | import java.util.Arrays; |
| 20 | import java.util.Objects; |
| 21 | import org.slf4j.Logger; |
| 22 | import org.slf4j.LoggerFactory; |
| 23 | |
| 24 | import com.google.common.base.MoreObjects; |
| 25 | |
| 26 | /** |
| 27 | * BGP flow specification type operator and value implementation. |
| 28 | */ |
| 29 | public class BgpFsOperatorValue { |
| 30 | |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 31 | private static final Logger log = LoggerFactory.getLogger(BgpFsOperatorValue.class); |
Shashikanth VH | 47c2da1 | 2016-02-04 18:58:15 +0530 | [diff] [blame] | 32 | |
| 33 | private final byte option; |
| 34 | private final byte[] value; |
| 35 | |
| 36 | /** |
| 37 | * constructor to initialize. |
| 38 | * |
| 39 | * @param option for a specific flow type |
| 40 | * @param value for a specific flow type |
| 41 | */ |
| 42 | public BgpFsOperatorValue(byte option, byte[] value) { |
| 43 | this.option = option; |
| 44 | this.value = Arrays.copyOf(value, value.length); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns option of the flow type. |
| 49 | * |
| 50 | * @return option of the flow type |
| 51 | */ |
| 52 | public byte option() { |
| 53 | return option; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns value of the flow type. |
| 58 | * |
| 59 | * @return value of the flow type |
| 60 | */ |
| 61 | public byte[] value() { |
| 62 | return value; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public int hashCode() { |
| 67 | return Objects.hash(option, Arrays.hashCode(value)); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public boolean equals(Object obj) { |
| 72 | if (this == obj) { |
| 73 | return true; |
| 74 | } |
| 75 | if (obj instanceof BgpFsOperatorValue) { |
| 76 | BgpFsOperatorValue other = (BgpFsOperatorValue) obj; |
| 77 | return Objects.equals(this.option, other.option) && Arrays.equals(this.value, other.value); |
| 78 | } |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public String toString() { |
| 84 | return MoreObjects.toStringHelper(getClass()).add("option", option).add("value", value).toString(); |
| 85 | } |
| 86 | } |