1 | package de.ugoe.cs.eventbench.jfc.data;
|
---|
2 |
|
---|
3 | import java.util.HashMap;
|
---|
4 | import java.util.Map;
|
---|
5 |
|
---|
6 | import de.ugoe.cs.eventbench.data.IReplayable;
|
---|
7 | import de.ugoe.cs.eventbench.data.ReplayableEvent;
|
---|
8 | import de.ugoe.cs.eventbench.jfc.JFCLogParser;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * <p>
|
---|
12 | * This class defines JFC events.
|
---|
13 | * </p>
|
---|
14 | *
|
---|
15 | * @author Steffen Herbold
|
---|
16 | * @version 1.0
|
---|
17 | */
|
---|
18 | public class JFCEvent extends ReplayableEvent<IReplayable> {
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * <p>
|
---|
22 | * Id for object serialization.
|
---|
23 | * </p>
|
---|
24 | */
|
---|
25 | private static final long serialVersionUID = 1L;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * <p>
|
---|
29 | * Internal map of parameters associated with the event.
|
---|
30 | * </p>
|
---|
31 | */
|
---|
32 | private Map<String, String> parameters;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * <p>
|
---|
36 | * Information about the event source.
|
---|
37 | * </p>
|
---|
38 | */
|
---|
39 | private Map<String, String> sourceParameters;
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * <p>
|
---|
43 | * Information about the parent of the event source.
|
---|
44 | * </p>
|
---|
45 | */
|
---|
46 | private Map<String, String> parentParameters;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * <p>
|
---|
50 | * Constructor. Creates a new JFCEvent.
|
---|
51 | * </p>
|
---|
52 | *
|
---|
53 | * @param type
|
---|
54 | * type of the event
|
---|
55 | */
|
---|
56 | public JFCEvent(String type) {
|
---|
57 | super(type);
|
---|
58 | parameters = new HashMap<String, String>();
|
---|
59 | sourceParameters = new HashMap<String, String>();
|
---|
60 | parentParameters = new HashMap<String, String>();
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * <p>
|
---|
65 | * Adds a new parameter to the event.
|
---|
66 | * </p>
|
---|
67 | *
|
---|
68 | * @param name
|
---|
69 | * name of the parameter
|
---|
70 | * @param value
|
---|
71 | * value of the parameter
|
---|
72 | */
|
---|
73 | public void addParameter(String name, String value) {
|
---|
74 | parameters.put(name, value);
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * <p>
|
---|
79 | * Retrieves the value of a parameter.
|
---|
80 | * </p>
|
---|
81 | *
|
---|
82 | * @param name
|
---|
83 | * name of the parameter
|
---|
84 | * @return value of the parameter
|
---|
85 | */
|
---|
86 | public String getParameter(String name) {
|
---|
87 | return parameters.get(name);
|
---|
88 | }
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * <p>
|
---|
92 | * Adds new information about the source of the event.
|
---|
93 | * </p>
|
---|
94 | *
|
---|
95 | * @param name
|
---|
96 | * name of the information
|
---|
97 | * @param value
|
---|
98 | * value of the information
|
---|
99 | */
|
---|
100 | public void addSourceInformation(String name, String value) {
|
---|
101 | sourceParameters.put(name, value);
|
---|
102 | }
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * <p>
|
---|
106 | * Retrieves information about the source of the event.
|
---|
107 | * </p>
|
---|
108 | *
|
---|
109 | * @param name
|
---|
110 | * name of the information
|
---|
111 | * @return value of the information
|
---|
112 | */
|
---|
113 | public String getSourceInformation(String name) {
|
---|
114 | return sourceParameters.get(name);
|
---|
115 | }
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * <p>
|
---|
119 | * Adds new information about the parent of the source of the event.
|
---|
120 | * </p>
|
---|
121 | *
|
---|
122 | * @param name
|
---|
123 | * name of the information
|
---|
124 | * @param value
|
---|
125 | * value of the information
|
---|
126 | */
|
---|
127 | public void addParentInformation(String name, String value) {
|
---|
128 | parentParameters.put(name, value);
|
---|
129 | }
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * <p>
|
---|
133 | * Used by the {@link JFCLogParser} to extend the target string of the
|
---|
134 | * current event with a further ancestor. The resulting target string will
|
---|
135 | * have the structure {@code etc.grandparent.parent.eventtarget}.
|
---|
136 | * </p>
|
---|
137 | *
|
---|
138 | * @param extension
|
---|
139 | * extension for the target.
|
---|
140 | */
|
---|
141 | public void extendTarget(String extension) {
|
---|
142 | if (target == null || "".equals(target)) {
|
---|
143 | target = extension;
|
---|
144 | } else {
|
---|
145 | target += "." + extension;
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * <p>
|
---|
151 | * Retrieves information about the parent of the source of the event.
|
---|
152 | * </p>
|
---|
153 | *
|
---|
154 | * @param name
|
---|
155 | * name of the information
|
---|
156 | * @return value of the information
|
---|
157 | */
|
---|
158 | public String getParentInformation(String name) {
|
---|
159 | return parentParameters.get(name);
|
---|
160 | }
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * <p>
|
---|
164 | * This method implements the comparison between two targets of JFCEvents.
|
---|
165 | * The targets are equal, if they have the same placement in the widget
|
---|
166 | * hierarchy, i.e., the target strings describe the same widgets, according
|
---|
167 | * to the implementation of widget equality provided by
|
---|
168 | * {@link #compareWidgets(String, String)}.
|
---|
169 | * </p>
|
---|
170 | *
|
---|
171 | * @see de.ugoe.cs.eventbench.data.Event#targetEquals(java.lang.String)
|
---|
172 | */
|
---|
173 | @Override
|
---|
174 | protected boolean targetEquals(String otherTarget) {
|
---|
175 | return JFCTargetComparator.compare(target, otherTarget);
|
---|
176 | }
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * <p>
|
---|
180 | * The targetHashCode ignores the parts of the target that describe the
|
---|
181 | * title and hash of a widget, to ensure that the equals/hashCode contract
|
---|
182 | * is fulfilled.
|
---|
183 | * </p>
|
---|
184 | *
|
---|
185 | * @see de.ugoe.cs.eventbench.data.Event#targetHashCode()
|
---|
186 | */
|
---|
187 | @Override
|
---|
188 | protected int targetHashCode() {
|
---|
189 | int hashCode = 0;
|
---|
190 | int multiplier = 29;
|
---|
191 | if (target != null) {
|
---|
192 | String[] targetParts = target.split("\\]\\.\\[");
|
---|
193 | if (targetParts.length == 0) {
|
---|
194 | hashCode = widgetHashCode(target);
|
---|
195 | } else {
|
---|
196 | for (String widgetString : targetParts) {
|
---|
197 | hashCode = hashCode * multiplier
|
---|
198 | + widgetHashCode(widgetString);
|
---|
199 | }
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | return hashCode;
|
---|
204 | }
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * <p>
|
---|
208 | * This method calculates the hashCode for a a widget. If is used by
|
---|
209 | * {@link #targetHashCode()} to build the complete hashCode.
|
---|
210 | * </p>
|
---|
211 | *
|
---|
212 | * @param widget
|
---|
213 | * string describing the widget
|
---|
214 | * @return hashCode of the widget
|
---|
215 | */
|
---|
216 | private int widgetHashCode(String widget) {
|
---|
217 | int hashCode = 0;
|
---|
218 | int multiplier = 37;
|
---|
219 | String[] widgetInfo = widget.split("','");
|
---|
220 | if (widgetInfo.length == 5) {
|
---|
221 | hashCode = hashCode * multiplier + widgetInfo[1].hashCode();
|
---|
222 | hashCode = hashCode * multiplier + widgetInfo[2].hashCode();
|
---|
223 | hashCode = hashCode * multiplier + widgetInfo[3].hashCode();
|
---|
224 | }
|
---|
225 | return hashCode;
|
---|
226 | }
|
---|
227 |
|
---|
228 | }
|
---|