blob: c98e7887f3b0b8fb91d7af802c5184c62dcdbbcf [file] [log] [blame]
Brian O'Connorb876bf12014-10-02 14:59:37 -07001package org.onlab.onos.net.intent;
2
toma1d16b62014-10-02 23:45:11 -07003import com.google.common.base.MoreObjects;
4import org.onlab.onos.event.AbstractEvent;
Brian O'Connorb876bf12014-10-02 14:59:37 -07005
6import java.util.Objects;
7
toma1d16b62014-10-02 23:45:11 -07008import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -07009
10/**
11 * A class to represent an intent related event.
12 */
Brian O'Connor66630c82014-10-02 21:08:19 -070013public class IntentEvent extends AbstractEvent<IntentState, Intent> {
Brian O'Connorb876bf12014-10-02 14:59:37 -070014
Brian O'Connor66630c82014-10-02 21:08:19 -070015 // TODO: determine a suitable parent class; if one does not exist, consider
16 // introducing one
Brian O'Connorb876bf12014-10-02 14:59:37 -070017
18 private final long time;
19 private final Intent intent;
20 private final IntentState state;
21 private final IntentState previous;
22
23 /**
24 * Creates an event describing a state change of an intent.
25 *
toma1d16b62014-10-02 23:45:11 -070026 * @param intent subject intent
27 * @param state new intent state
Brian O'Connorb876bf12014-10-02 14:59:37 -070028 * @param previous previous intent state
toma1d16b62014-10-02 23:45:11 -070029 * @param time time the event created in milliseconds since start of epoch
Brian O'Connorb876bf12014-10-02 14:59:37 -070030 * @throws NullPointerException if the intent or state is null
31 */
32 public IntentEvent(Intent intent, IntentState state, IntentState previous, long time) {
Brian O'Connor66630c82014-10-02 21:08:19 -070033 super(state, intent);
Brian O'Connorb876bf12014-10-02 14:59:37 -070034 this.intent = checkNotNull(intent);
35 this.state = checkNotNull(state);
36 this.previous = previous;
37 this.time = time;
38 }
39
40 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -070041 * Returns the state of the intent which caused the event.
42 *
43 * @return the state of the intent
44 */
45 public IntentState getState() {
46 return state;
47 }
48
49 /**
50 * Returns the previous state of the intent which caused the event.
51 *
52 * @return the previous state of the intent
53 */
54 public IntentState getPreviousState() {
55 return previous;
56 }
57
58 /**
59 * Returns the intent associated with the event.
60 *
61 * @return the intent
62 */
63 public Intent getIntent() {
64 return intent;
65 }
66
67 /**
68 * Returns the time at which the event was created.
69 *
70 * @return the time in milliseconds since start of epoch
71 */
72 public long getTime() {
73 return time;
74 }
75
76 @Override
77 public boolean equals(Object o) {
78 if (this == o) {
79 return true;
80 }
81 if (o == null || getClass() != o.getClass()) {
82 return false;
83 }
84
85 IntentEvent that = (IntentEvent) o;
86 return Objects.equals(this.intent, that.intent)
87 && Objects.equals(this.state, that.state)
88 && Objects.equals(this.previous, that.previous)
89 && Objects.equals(this.time, that.time);
90 }
91
92 @Override
93 public int hashCode() {
94 return Objects.hash(intent, state, previous, time);
95 }
96
97 @Override
98 public String toString() {
99 return MoreObjects.toStringHelper(getClass())
100 .add("intent", intent)
101 .add("state", state)
102 .add("previous", previous)
103 .add("time", time)
104 .toString();
105 }
106}