blob: 670e87ed537dbd94b62dbd8da0c0d9a73b89c5f7 [file] [log] [blame]
Sho SHIMIZU15ed4fd2014-08-05 14:40:42 -07001package net.onrc.onos.api.newintent;
2
3import com.google.common.base.Objects;
4
5import static com.google.common.base.Preconditions.checkNotNull;
6
7/**
8 * A class to represent an intent related event.
9 */
10public class IntentEvent {
11
12 // TODO: determine a suitable parent class; if one does not exist, consider introducing one
13
14 private final long time;
15 private final Intent intent;
16 private final IntentState state;
17 private final IntentState previous;
18
19 /**
20 * Creates an event describing a state change of an intent.
21 *
22 * @param intent subject intent
23 * @param state new intent state
24 * @param previous previous intent state
25 * @param time time the event created in milliseconds since start of epoch
26 * @throws NullPointerException if the intent or state is null
27 */
28 public IntentEvent(Intent intent, IntentState state, IntentState previous, long time) {
29 this.intent = checkNotNull(intent);
30 this.state = checkNotNull(state);
31 this.previous = previous;
32 this.time = time;
33 }
34
35 /**
36 * Returns the state of the intent which caused the event.
37 *
38 * @return the state of the intent
39 */
40 public IntentState getState() {
41 return state;
42 }
43
44 /**
45 * Returns the previous state of the intent which caused the event.
46 *
47 * @return the previous state of the intent
48 */
49 public IntentState getPreviousState() {
50 return previous;
51 }
52
53 /**
54 * Returns the intent associated with the event.
55 *
56 * @return the intent
57 */
58 public Intent getIntent() {
59 return intent;
60 }
61
62 /**
63 * Returns the time at which the event was created.
64 *
65 * @return the time in milliseconds since start of epoch
66 */
67 public long getTime() {
68 return time;
69 }
70
71 @Override
72 public boolean equals(Object o) {
73 if (this == o) {
74 return true;
75 }
76 if (o == null || getClass() != o.getClass()) {
77 return false;
78 }
79
80 IntentEvent that = (IntentEvent) o;
81 return Objects.equal(this.intent, that.intent)
82 && Objects.equal(this.state, that.state)
83 && Objects.equal(this.previous, that.previous)
84 && Objects.equal(this.time, that.time);
85 }
86
87 @Override
88 public int hashCode() {
89 return Objects.hashCode(intent, state, previous, time);
90 }
91
92 @Override
93 public String toString() {
94 return Objects.toStringHelper(getClass())
95 .add("intent", intent)
96 .add("state", state)
97 .add("previous", previous)
98 .add("time", time)
99 .toString();
100 }
101}