Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.util; |
Pavlin Radoslavov | 3f9ba65 | 2013-10-25 17:19:01 -0700 | [diff] [blame] | 2 | |
| 3 | /** |
| 4 | * Class for encapsulating events with event-related data entry. |
| 5 | */ |
| 6 | public class EventEntry<T> { |
| 7 | /** |
| 8 | * The event types. |
| 9 | */ |
| 10 | public enum Type { |
Pavlin Radoslavov | 054cd59 | 2014-08-07 20:57:16 -0700 | [diff] [blame] | 11 | ENTRY_ADD, // Add or update an entry |
| 12 | ENTRY_REMOVE, // Remove an entry |
| 13 | ENTRY_NOOP // NO-OP event (No Operation) |
Pavlin Radoslavov | 3f9ba65 | 2013-10-25 17:19:01 -0700 | [diff] [blame] | 14 | } |
| 15 | |
Pavlin Radoslavov | 054cd59 | 2014-08-07 20:57:16 -0700 | [diff] [blame] | 16 | private Type eventType; // The event type |
| 17 | private T eventData; // The relevant event data entry |
Pavlin Radoslavov | 3f9ba65 | 2013-10-25 17:19:01 -0700 | [diff] [blame] | 18 | |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 26 | this.eventType = eventType; |
| 27 | this.eventData = eventData; |
Pavlin Radoslavov | 3f9ba65 | 2013-10-25 17:19:01 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | /** |
Pavlin Radoslavov | 054cd59 | 2014-08-07 20:57:16 -0700 | [diff] [blame] | 31 | * 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 Radoslavov | 3f9ba65 | 2013-10-25 17:19:01 -0700 | [diff] [blame] | 47 | * |
| 48 | * @return true if the event type is ENTRY_ADD, otherwise false. |
| 49 | */ |
| 50 | public boolean isAdd() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 51 | return (this.eventType == Type.ENTRY_ADD); |
Pavlin Radoslavov | 3f9ba65 | 2013-10-25 17:19:01 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
Pavlin Radoslavov | 054cd59 | 2014-08-07 20:57:16 -0700 | [diff] [blame] | 55 | * Tests whether the event type is ENTRY_REMOVE. |
Pavlin Radoslavov | 3f9ba65 | 2013-10-25 17:19:01 -0700 | [diff] [blame] | 56 | * |
| 57 | * @return true if the event type is ENTRY_REMOVE, otherwise false. |
| 58 | */ |
| 59 | public boolean isRemove() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 60 | return (this.eventType == Type.ENTRY_REMOVE); |
Pavlin Radoslavov | 3f9ba65 | 2013-10-25 17:19:01 -0700 | [diff] [blame] | 61 | } |
Pavlin Radoslavov | c91d6e3 | 2013-10-26 21:26:47 -0700 | [diff] [blame] | 62 | |
| 63 | /** |
Pavlin Radoslavov | 054cd59 | 2014-08-07 20:57:16 -0700 | [diff] [blame] | 64 | * 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 Radoslavov | 7ac39ff | 2013-10-27 19:55:00 -0700 | [diff] [blame] | 74 | * |
| 75 | * @return the event type. |
| 76 | */ |
| 77 | public EventEntry.Type eventType() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 78 | return this.eventType; |
Pavlin Radoslavov | 7ac39ff | 2013-10-27 19:55:00 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /** |
Pavlin Radoslavov | 054cd59 | 2014-08-07 20:57:16 -0700 | [diff] [blame] | 82 | * Gets the event-related data entry. |
Pavlin Radoslavov | c91d6e3 | 2013-10-26 21:26:47 -0700 | [diff] [blame] | 83 | * |
| 84 | * @return the event-related data entry. |
| 85 | */ |
| 86 | public T eventData() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 87 | return this.eventData; |
Pavlin Radoslavov | c91d6e3 | 2013-10-26 21:26:47 -0700 | [diff] [blame] | 88 | } |
Pavlin Radoslavov | 3f9ba65 | 2013-10-25 17:19:01 -0700 | [diff] [blame] | 89 | } |