1 | package de.ugoe.cs.eventbench.data;
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 | public class Event<T> {
|
---|
6 |
|
---|
7 | public static final Event<Object> STARTEVENT = new Event<Object>("START");
|
---|
8 | public static final Event<Object> ENDEVENT = new Event<Object>("END");
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * <p>
|
---|
12 | * Type of the event.
|
---|
13 | * </p>
|
---|
14 | */
|
---|
15 | private String type;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * </p>
|
---|
19 | * Target of the event.
|
---|
20 | */
|
---|
21 | private String target = null;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * <p>
|
---|
25 | * Short description of the event target.
|
---|
26 | * </p>
|
---|
27 | */
|
---|
28 | private String targetShort = null;
|
---|
29 |
|
---|
30 |
|
---|
31 | private String idInfo = "";
|
---|
32 |
|
---|
33 | public Event(String type) {
|
---|
34 | this.type = type;
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | public boolean equals(Object other) {
|
---|
39 | if( this==other ) {
|
---|
40 | return true;
|
---|
41 | }
|
---|
42 | if (other instanceof Event<?>) {
|
---|
43 | Event<?> otherToken = (Event<?>) other;
|
---|
44 | return otherToken.type.equals(this.type)
|
---|
45 | && otherToken.target.equals(this.target);
|
---|
46 | } else {
|
---|
47 | return false;
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public String toString() {
|
---|
53 | return getStandardId();
|
---|
54 | }
|
---|
55 |
|
---|
56 | public String getIdInfo() {
|
---|
57 | return idInfo;
|
---|
58 | }
|
---|
59 |
|
---|
60 | public String getShortId() {
|
---|
61 | String shortId = null;
|
---|
62 | if (targetShort!=null) {
|
---|
63 | shortId = targetShort+"."+getType();
|
---|
64 | if (idInfo!="") {
|
---|
65 | shortId += "."+idInfo;
|
---|
66 | }
|
---|
67 | }
|
---|
68 | return shortId;
|
---|
69 | }
|
---|
70 |
|
---|
71 | public String getStandardId() {
|
---|
72 | String id = target + "." + getType();
|
---|
73 | if ( idInfo!="" ) {
|
---|
74 | id += "." + idInfo;
|
---|
75 | }
|
---|
76 | return id;
|
---|
77 | }
|
---|
78 |
|
---|
79 | public String getTarget() {
|
---|
80 | return target;
|
---|
81 | }
|
---|
82 |
|
---|
83 | public String getTargetShort() {
|
---|
84 | return targetShort;
|
---|
85 | }
|
---|
86 |
|
---|
87 | public String getType() {
|
---|
88 | return type;
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Override
|
---|
92 | public int hashCode() {
|
---|
93 | int multiplier = 17;
|
---|
94 | int hash = 42;
|
---|
95 | hash = multiplier * hash + type.hashCode();
|
---|
96 | if( target!=null ) {
|
---|
97 | hash = multiplier * hash + target.hashCode();
|
---|
98 | }
|
---|
99 |
|
---|
100 | return hash;
|
---|
101 | }
|
---|
102 |
|
---|
103 | public void setIdInfo(String info) {
|
---|
104 | idInfo = info;
|
---|
105 | }
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * <p>
|
---|
109 | * Sets the target of the event. Once set, the target cannot be changed.
|
---|
110 | * </p>
|
---|
111 | * @param target target of the event
|
---|
112 | * @return true, if target was changed, false otherwise
|
---|
113 | */
|
---|
114 | public boolean setTarget(String target) {
|
---|
115 | if( this.target!=null ) {
|
---|
116 | return false;
|
---|
117 | }
|
---|
118 | this.target = target;
|
---|
119 | return true;
|
---|
120 | }
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * <p>
|
---|
124 | * Sets the short description of the event target. Once set, the target cannot be changed.
|
---|
125 | * </p>
|
---|
126 | * @param targetShort short target description
|
---|
127 | * @return true, if target was changed, false otherwise
|
---|
128 | */
|
---|
129 | public boolean setTargetShort(String targetShort) {
|
---|
130 | if( this.targetShort!=null ) {
|
---|
131 | return false;
|
---|
132 | }
|
---|
133 | this.targetShort = targetShort;
|
---|
134 | return true;
|
---|
135 | }
|
---|
136 | }
|
---|