blob: e1abcaf627d758c3ef1639bc4a07d71014ee2298 [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 {
Ray Milkey269ffb92014-04-03 14:43:30 -070011 ENTRY_ADD, // Add or update an entry
12 ENTRY_REMOVE // Remove an entry
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070013 }
14
Ray Milkey269ffb92014-04-03 14:43:30 -070015 private Type eventType; // The event type
16 private T eventData; // The relevant event data entry
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070017
18 /**
19 * Constructor for a given event type and event-related data entry.
20 *
21 * @param eventType the event type.
22 * @param eventData the event data entry.
23 */
24 public EventEntry(EventEntry.Type eventType, T eventData) {
Ray Milkey269ffb92014-04-03 14:43:30 -070025 this.eventType = eventType;
26 this.eventData = eventData;
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070027 }
28
29 /**
30 * Test whether the event type is ENTRY_ADD.
31 *
32 * @return true if the event type is ENTRY_ADD, otherwise false.
33 */
34 public boolean isAdd() {
Ray Milkey269ffb92014-04-03 14:43:30 -070035 return (this.eventType == Type.ENTRY_ADD);
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070036 }
37
38 /**
39 * Test whether the event type is ENTRY_REMOVE.
40 *
41 * @return true if the event type is ENTRY_REMOVE, otherwise false.
42 */
43 public boolean isRemove() {
Ray Milkey269ffb92014-04-03 14:43:30 -070044 return (this.eventType == Type.ENTRY_REMOVE);
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070045 }
Pavlin Radoslavovc91d6e32013-10-26 21:26:47 -070046
47 /**
Pavlin Radoslavov7ac39ff2013-10-27 19:55:00 -070048 * Get the event type.
49 *
50 * @return the event type.
51 */
52 public EventEntry.Type eventType() {
Ray Milkey269ffb92014-04-03 14:43:30 -070053 return this.eventType;
Pavlin Radoslavov7ac39ff2013-10-27 19:55:00 -070054 }
55
56 /**
Pavlin Radoslavovc91d6e32013-10-26 21:26:47 -070057 * Get the event-related data entry.
58 *
59 * @return the event-related data entry.
60 */
61 public T eventData() {
Ray Milkey269ffb92014-04-03 14:43:30 -070062 return this.eventData;
Pavlin Radoslavovc91d6e32013-10-26 21:26:47 -070063 }
Pavlin Radoslavov3f9ba652013-10-25 17:19:01 -070064}