blob: 088f68f2ca6986dfc04eb8f32b92f07d34981c9e [file] [log] [blame]
Shashikanth VH47c2da12016-02-04 18:58:15 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Shashikanth VH47c2da12016-02-04 18:58:15 +05303 *
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
17package org.onosproject.bgpio.types;
18
19import java.util.Arrays;
20import java.util.Objects;
21import org.slf4j.Logger;
22import org.slf4j.LoggerFactory;
23
24import com.google.common.base.MoreObjects;
25
26/**
27 * BGP flow specification type operator and value implementation.
28 */
29public class BgpFsOperatorValue {
30
Ray Milkey9c9cde42018-01-12 14:22:06 -080031 private static final Logger log = LoggerFactory.getLogger(BgpFsOperatorValue.class);
Shashikanth VH47c2da12016-02-04 18:58:15 +053032
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}