blob: 7d1e93d18d3a56b7f378579e3df4ba33efeb9428 [file] [log] [blame]
Charles Chanf7b1b4b2019-01-16 15:30:39 -08001/*
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 */
16package org.onosproject.portloadbalancer.api;
17
18
19import java.util.Objects;
20
21import static com.google.common.base.MoreObjects.toStringHelper;
22
23/**
24 * Represents port load balancer event data.
25 */
26public class PortLoadBalancerData {
27
28 // We exchange only id and nextid in the events
29 private PortLoadBalancerId portLoadBalancerId;
30 private int nextId;
31
32 /**
33 * Constructs a port load balancer data.
34 *
35 * @param portLoadBalancerId port load balancer ID
36 */
37 public PortLoadBalancerData(PortLoadBalancerId portLoadBalancerId) {
38 this.portLoadBalancerId = portLoadBalancerId;
39 this.nextId = -1;
40 }
41
42 /**
43 * Constructs a port load balancer data.
44 *
45 * @param portLoadBalancerId port load balancer ID
46 * @param nextId port load balancer next id
47 */
48 public PortLoadBalancerData(PortLoadBalancerId portLoadBalancerId, int nextId) {
49 this.portLoadBalancerId = portLoadBalancerId;
50 this.nextId = nextId;
51 }
52
53 /**
54 * Gets port load balancer ID.
55 *
56 * @return port load balancer ID
57 */
58 public PortLoadBalancerId portLoadBalancerId() {
59 return portLoadBalancerId;
60 }
61
62 /**
63 * Gets port load balancer next id.
64 *
65 * @return port load balancer next id
66 */
67 public int nextId() {
68 return nextId;
69 }
70
71 /**
72 * Sets port load balancer next id.
73 *
74 * @param nextId port load balancer next id
75 */
76 public void setNextId(int nextId) {
77 this.nextId = nextId;
78 }
79
80 @Override
81 public int hashCode() {
82 return Objects.hash(portLoadBalancerId, nextId);
83 }
84
85 @Override
86 public boolean equals(final Object obj) {
87 if (this == obj) {
88 return true;
89 }
90 if (!(obj instanceof PortLoadBalancerData)) {
91 return false;
92 }
93 final PortLoadBalancerData other = (PortLoadBalancerData) obj;
94
95 return Objects.equals(this.portLoadBalancerId, other.portLoadBalancerId) &&
96 this.nextId == other.nextId;
97 }
98
99 @Override
100 public String toString() {
101 return toStringHelper(getClass())
102 .add("portLoadBalancerId", portLoadBalancerId)
103 .add("nextId", nextId)
104 .toString();
105 }
106}