blob: d19a1ac012129e878a892111d13dfcda0eb04e8d [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.util;
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -07002
3/**
4 * Class for encapsulating events with event-related data entry.
5 */
6public class EventEntry<T> {
7 /**
8 * The event types.
9 */
10 public enum Type {
Pavlin Radoslavov054cd592014-08-07 20:57:16 -070011 ENTRY_ADD, // Add or update an entry
12 ENTRY_REMOVE, // Remove an entry
13 ENTRY_NOOP // NO-OP event (No Operation)
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070014 }
15
Pavlin Radoslavov054cd592014-08-07 20:57:16 -070016 private Type eventType; // The event type
17 private T eventData; // The relevant event data entry
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070018
19 /**
20 * Constructor for a given event type and event-related data entry.
21 *
22 * @param eventType the event type.
23 * @param eventData the event data entry.
24 */
25 public EventEntry(EventEntry.Type eventType, T eventData) {
Ray Milkey269ffb92014-04-03 14:43:30 -070026 this.eventType = eventType;
27 this.eventData = eventData;
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070028 }
29
30 /**
Pavlin Radoslavov054cd592014-08-07 20:57:16 -070031 * Creates a NO-OP event.
32 * <p/>
33 * This is a factory method that can be called without an object:
34 * <p/>
35 * <code>
36 * EventEntry<TopologyEvent> eventEntry = EventEntry.makeNoop();
37 * </code>
38 *
39 * @return a NO-OP event.
40 */
41 public static <T> EventEntry<T> makeNoop() {
42 return new EventEntry<T>(Type.ENTRY_NOOP, null);
43 }
44
45 /**
46 * Tests whether the event type is ENTRY_ADD.
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070047 *
48 * @return true if the event type is ENTRY_ADD, otherwise false.
49 */
50 public boolean isAdd() {
Ray Milkey269ffb92014-04-03 14:43:30 -070051 return (this.eventType == Type.ENTRY_ADD);
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070052 }
53
54 /**
Pavlin Radoslavov054cd592014-08-07 20:57:16 -070055 * Tests whether the event type is ENTRY_REMOVE.
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070056 *
57 * @return true if the event type is ENTRY_REMOVE, otherwise false.
58 */
59 public boolean isRemove() {
Ray Milkey269ffb92014-04-03 14:43:30 -070060 return (this.eventType == Type.ENTRY_REMOVE);
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070061 }
Pavlin Radoslavovc91d6e32013-10-26 21:26:47 -070062
63 /**
Pavlin Radoslavov054cd592014-08-07 20:57:16 -070064 * Tests whether the event type is ENTRY_NOOP.
65 *
66 * @return true if the event type is ENTRY_NOOP, otherwise false.
67 */
68 public boolean isNoop() {
69 return (this.eventType == Type.ENTRY_NOOP);
70 }
71
72 /**
73 * Gets the event type.
Pavlin Radoslavov7ac39ff2013-10-27 19:55:00 -070074 *
75 * @return the event type.
76 */
77 public EventEntry.Type eventType() {
Ray Milkey269ffb92014-04-03 14:43:30 -070078 return this.eventType;
Pavlin Radoslavov7ac39ff2013-10-27 19:55:00 -070079 }
80
81 /**
Pavlin Radoslavov054cd592014-08-07 20:57:16 -070082 * Gets the event-related data entry.
Pavlin Radoslavovc91d6e32013-10-26 21:26:47 -070083 *
84 * @return the event-related data entry.
85 */
86 public T eventData() {
Ray Milkey269ffb92014-04-03 14:43:30 -070087 return this.eventData;
Pavlin Radoslavovc91d6e32013-10-26 21:26:47 -070088 }
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070089}