blob: 3dcf2a8038ff1e2959d62c0a4f0eedf9a7b47ccf [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 /**
Sho SHIMIZU1674fb32014-08-20 14:44:31 -070036 * Constructor for serializer.
37 */
38 protected IntentEvent() {
39 this.intent = null;
40 this.state = null;
41 this.previous = null;
42 this.time = 0;
43 }
44
45 /**
Sho SHIMIZU15ed4fd2014-08-05 14:40:42 -070046 * Returns the state of the intent which caused the event.
47 *
48 * @return the state of the intent
49 */
50 public IntentState getState() {
51 return state;
52 }
53
54 /**
55 * Returns the previous state of the intent which caused the event.
56 *
57 * @return the previous state of the intent
58 */
59 public IntentState getPreviousState() {
60 return previous;
61 }
62
63 /**
64 * Returns the intent associated with the event.
65 *
66 * @return the intent
67 */
68 public Intent getIntent() {
69 return intent;
70 }
71
72 /**
73 * Returns the time at which the event was created.
74 *
75 * @return the time in milliseconds since start of epoch
76 */
77 public long getTime() {
78 return time;
79 }
80
81 @Override
82 public boolean equals(Object o) {
83 if (this == o) {
84 return true;
85 }
86 if (o == null || getClass() != o.getClass()) {
87 return false;
88 }
89
90 IntentEvent that = (IntentEvent) o;
91 return Objects.equal(this.intent, that.intent)
92 && Objects.equal(this.state, that.state)
93 && Objects.equal(this.previous, that.previous)
94 && Objects.equal(this.time, that.time);
95 }
96
97 @Override
98 public int hashCode() {
99 return Objects.hashCode(intent, state, previous, time);
100 }
101
102 @Override
103 public String toString() {
104 return Objects.toStringHelper(getClass())
105 .add("intent", intent)
106 .add("state", state)
107 .add("previous", previous)
108 .add("time", time)
109 .toString();
110 }
111}