1 | package geniusweb.events;
|
---|
2 |
|
---|
3 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
4 | import com.fasterxml.jackson.annotation.JsonProperty;
|
---|
5 | import com.fasterxml.jackson.annotation.JsonTypeName;
|
---|
6 |
|
---|
7 | import geniusweb.actions.Action;
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * Event where a party did an {@link Action}
|
---|
11 | *
|
---|
12 | */
|
---|
13 | @JsonTypeName("actionevent")
|
---|
14 | public class ActionEvent extends AbstractEvent {
|
---|
15 |
|
---|
16 | private final Action action;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | *
|
---|
20 | * @param action the {@link Action} that was done
|
---|
21 | * @param time the current time to use. see
|
---|
22 | * {@link System#currentTimeMillis()}.
|
---|
23 | */
|
---|
24 | @JsonCreator
|
---|
25 | public ActionEvent(@JsonProperty("action") Action action,
|
---|
26 | @JsonProperty("time") Long time) {
|
---|
27 | super(time);
|
---|
28 | if (action == null) {
|
---|
29 | throw new IllegalArgumentException("Action must not be null");
|
---|
30 | }
|
---|
31 | this.action = action;
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | *
|
---|
36 | * @return action done by some party in the system.
|
---|
37 | */
|
---|
38 | public Action getAction() {
|
---|
39 | return action;
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public String toString() {
|
---|
44 | return this.getClass().getSimpleName() + "[" + getTime() + "," + action
|
---|
45 | + "]";
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public int hashCode() {
|
---|
50 | final int prime = 31;
|
---|
51 | int result = super.hashCode();
|
---|
52 | result = prime * result + ((action == null) ? 0 : action.hashCode());
|
---|
53 | return result;
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public boolean equals(Object obj) {
|
---|
58 | if (this == obj)
|
---|
59 | return true;
|
---|
60 | if (!super.equals(obj))
|
---|
61 | return false;
|
---|
62 | if (getClass() != obj.getClass())
|
---|
63 | return false;
|
---|
64 | ActionEvent other = (ActionEvent) obj;
|
---|
65 | if (action == null) {
|
---|
66 | if (other.action != null)
|
---|
67 | return false;
|
---|
68 | } else if (!action.equals(other.action))
|
---|
69 | return false;
|
---|
70 | return true;
|
---|
71 | }
|
---|
72 |
|
---|
73 | }
|
---|