Madan Jampani | 619453b | 2015-07-22 23:47:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | */ |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 16 | package org.onosproject.store.service; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | |
| 22 | /** |
| 23 | * Representation of a DistributedSet update notification. |
| 24 | * |
Madan Jampani | cab114c | 2015-07-23 00:14:19 -0700 | [diff] [blame] | 25 | * @param <E> set element type |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 26 | */ |
Ray Milkey | 67d53cc | 2015-07-23 16:32:36 -0700 | [diff] [blame] | 27 | public final class SetEvent<E> { |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 28 | |
| 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 Jampani | cab114c | 2015-07-23 00:14:19 -0700 | [diff] [blame] | 52 | * @param type type of the event |
| 53 | * @param entry entry the event concerns |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 54 | */ |
| 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 Jampani | cab114c | 2015-07-23 00:14:19 -0700 | [diff] [blame] | 73 | * @return type of the event |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 74 | */ |
| 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 Milkey | 67d53cc | 2015-07-23 16:32:36 -0700 | [diff] [blame] | 94 | SetEvent that = (SetEvent) o; |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 95 | 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 | } |