blob: ee7d42efb771ae985577ad17ea4e889969fb2484 [file] [log] [blame]
Jonathan Hartdb3af892015-01-26 13:19:07 -08001/*
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 */
Jonathan Hart77bdd262015-02-03 09:07:48 -080016package org.onosproject.store.ecmap;
Jonathan Hartdb3af892015-01-26 13:19:07 -080017
Jonathan Hart584d2f32015-01-27 19:46:14 -080018import com.google.common.base.MoreObjects;
19
20import java.util.Objects;
21
Jonathan Hartdb3af892015-01-26 13:19:07 -080022/**
23 * Event object signalling that the map was modified.
24 */
25public class EventuallyConsistentMapEvent<K, V> {
26
27 public enum Type {
28 PUT,
29 REMOVE
30 }
31
32 private final Type type;
33 private final K key;
34 private final V value;
35
36 /**
37 * Creates a new event object.
38 *
39 * @param type the type of the event
40 * @param key the key the event concerns
41 * @param value the value related to the key, or null for remove events
42 */
43 public EventuallyConsistentMapEvent(Type type, K key, V value) {
44 this.type = type;
45 this.key = key;
46 this.value = value;
47 }
48
49 /**
50 * Returns the type of the event.
51 *
52 * @return the type of the event
53 */
54 public Type type() {
55 return type;
56 }
57
58 /**
59 * Returns the key this event concerns.
60 *
61 * @return the key
62 */
63 public K key() {
64 return key;
65 }
66
67 /**
68 * Returns the value associated with this event.
69 *
70 * @return the value, or null if the event was REMOVE
71 */
72 public V value() {
73 return value;
74 }
Jonathan Hart584d2f32015-01-27 19:46:14 -080075
76 @Override
77 public boolean equals(Object o) {
78 if (!(o instanceof EventuallyConsistentMapEvent)) {
79 return false;
80 }
81
82 EventuallyConsistentMapEvent that = (EventuallyConsistentMapEvent) o;
83 return Objects.equals(this.type, that.type) &&
84 Objects.equals(this.key, that.key) &&
85 Objects.equals(this.value, that.value);
86 }
87
88 @Override
89 public int hashCode() {
90 return Objects.hash(type, key, value);
91 }
92
93 @Override
94 public String toString() {
95 return MoreObjects.toStringHelper(getClass())
96 .add("type", type)
97 .add("key", key)
98 .add("value", value)
99 .toString();
100 }
Jonathan Hartdb3af892015-01-26 13:19:07 -0800101}