blob: 451acacbf4a839987f552726d50622bddd365099 [file] [log] [blame]
Madan Jampani619453b2015-07-22 23:47:09 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Madan Jampani619453b2015-07-22 23:47:09 -07003 *
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 */
Madan Jampani50589ac2015-06-08 11:38:46 -070016package org.onosproject.store.service;
17
18import java.util.Objects;
19
20import com.google.common.base.MoreObjects;
21
22/**
23 * Representation of a DistributedSet update notification.
24 *
Madan Jampanicab114c2015-07-23 00:14:19 -070025 * @param <E> set element type
Madan Jampani50589ac2015-06-08 11:38:46 -070026 */
Ray Milkey67d53cc2015-07-23 16:32:36 -070027public final class SetEvent<E> {
Madan Jampani50589ac2015-06-08 11:38:46 -070028
29 /**
30 * SetEvent type.
31 */
32 public enum Type {
33 /**
34 * Entry added to the set.
35 */
36 ADD,
37
38 /**
39 * Entry removed from the set.
40 */
41 REMOVE
42 }
43
44 private final String name;
45 private final Type type;
46 private final E entry;
47
48 /**
49 * Creates a new event object.
50 *
51 * @param name set name
Madan Jampanicab114c2015-07-23 00:14:19 -070052 * @param type type of the event
53 * @param entry entry the event concerns
Madan Jampani50589ac2015-06-08 11:38:46 -070054 */
55 public SetEvent(String name, Type type, E entry) {
56 this.name = name;
57 this.type = type;
58 this.entry = entry;
59 }
60
61 /**
62 * Returns the set name.
63 *
64 * @return name of set
65 */
66 public String name() {
67 return name;
68 }
69
70 /**
71 * Returns the type of the event.
72 *
Madan Jampanicab114c2015-07-23 00:14:19 -070073 * @return type of the event
Madan Jampani50589ac2015-06-08 11:38:46 -070074 */
75 public Type type() {
76 return type;
77 }
78
79 /**
80 * Returns the entry this event concerns.
81 *
82 * @return the entry
83 */
84 public E entry() {
85 return entry;
86 }
87
88 @Override
89 public boolean equals(Object o) {
90 if (!(o instanceof SetEvent)) {
91 return false;
92 }
93
Ray Milkey67d53cc2015-07-23 16:32:36 -070094 SetEvent that = (SetEvent) o;
Madan Jampani50589ac2015-06-08 11:38:46 -070095 return Objects.equals(this.name, that.name) &&
96 Objects.equals(this.type, that.type) &&
97 Objects.equals(this.entry, that.entry);
98 }
99
100 @Override
101 public int hashCode() {
102 return Objects.hash(name, type, entry);
103 }
104
105 @Override
106 public String toString() {
107 return MoreObjects.toStringHelper(getClass())
108 .add("name", name)
109 .add("type", type)
110 .add("entry", entry)
111 .toString();
112 }
113}