blob: f0ac847c8f4e2cac49f0e0a54e768050bd882e82 [file] [log] [blame]
Charles Chan7f987c52018-07-31 18:22:46 -07001/*
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
17package org.onosproject.l2lb.api;
18
19import org.onlab.util.Tools;
20import org.onosproject.event.AbstractEvent;
21import java.util.Objects;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24
25public class L2LbEvent extends AbstractEvent<L2LbEvent.Type, L2Lb> {
26
27 private L2Lb prevSubject;
28
29 /**
30 * L2 load balancer event type.
31 */
32 public enum Type {
33 ADDED,
34 REMOVED,
35 UPDATED
36 }
37
38 /**
39 * Constructs a L2 load balancer event.
40 *
41 * @param type event type
42 * @param subject current L2 load balancer information
43 * @param prevSubject previous L2 load balancer information
44 */
45 public L2LbEvent(Type type, L2Lb subject, L2Lb prevSubject) {
46 super(type, subject);
47 this.prevSubject = prevSubject;
48 }
49
50 /**
51 * Gets previous L2 load balancer information.
52 *
53 * @return previous subject
54 */
55 public L2Lb prevSubject() {
56 return prevSubject;
57 }
58
59 @Override
60 public int hashCode() {
61 return Objects.hash(subject(), time(), prevSubject);
62 }
63
64 @Override
65 public boolean equals(Object other) {
66 if (this == other) {
67 return true;
68 }
69
70 if (!(other instanceof L2LbEvent)) {
71 return false;
72 }
73
74 L2LbEvent that = (L2LbEvent) other;
75 return Objects.equals(this.subject(), that.subject()) &&
76 Objects.equals(this.type(), that.type()) &&
77 Objects.equals(this.prevSubject, that.prevSubject);
78 }
79
80 @Override
81 public String toString() {
82 return toStringHelper(this)
83 .add("type", type())
84 .add("subject", subject())
85 .add("prevSubject", prevSubject)
86 .add("time", Tools.defaultOffsetDataTime(time()))
87 .toString();
88 }
89}