blob: 1296a8ba6ece6a0317fe607e0d43c0dc0104f701 [file] [log] [blame]
Madan Jampani50589ac2015-06-08 11:38:46 -07001package org.onosproject.store.service;
2
3import java.util.Objects;
4
5import com.google.common.base.MoreObjects;
6
7/**
8 * Representation of a DistributedSet update notification.
9 *
10 * @param <E> element type
11 */
12public class SetEvent<E> {
13
14 /**
15 * SetEvent type.
16 */
17 public enum Type {
18 /**
19 * Entry added to the set.
20 */
21 ADD,
22
23 /**
24 * Entry removed from the set.
25 */
26 REMOVE
27 }
28
29 private final String name;
30 private final Type type;
31 private final E entry;
32
33 /**
34 * Creates a new event object.
35 *
36 * @param name set name
37 * @param type the type of the event
38 * @param entry the entry the event concerns
39 */
40 public SetEvent(String name, Type type, E entry) {
41 this.name = name;
42 this.type = type;
43 this.entry = entry;
44 }
45
46 /**
47 * Returns the set name.
48 *
49 * @return name of set
50 */
51 public String name() {
52 return name;
53 }
54
55 /**
56 * Returns the type of the event.
57 *
58 * @return the type of the event
59 */
60 public Type type() {
61 return type;
62 }
63
64 /**
65 * Returns the entry this event concerns.
66 *
67 * @return the entry
68 */
69 public E entry() {
70 return entry;
71 }
72
73 @Override
74 public boolean equals(Object o) {
75 if (!(o instanceof SetEvent)) {
76 return false;
77 }
78
79 SetEvent<E> that = (SetEvent) o;
80 return Objects.equals(this.name, that.name) &&
81 Objects.equals(this.type, that.type) &&
82 Objects.equals(this.entry, that.entry);
83 }
84
85 @Override
86 public int hashCode() {
87 return Objects.hash(name, type, entry);
88 }
89
90 @Override
91 public String toString() {
92 return MoreObjects.toStringHelper(getClass())
93 .add("name", name)
94 .add("type", type)
95 .add("entry", entry)
96 .toString();
97 }
98}