package de.ugoe.cs.eventbench.jfc.data; import java.util.HashMap; import java.util.Map; import de.ugoe.cs.eventbench.data.IReplayable; import de.ugoe.cs.eventbench.data.ReplayableEvent; import de.ugoe.cs.eventbench.jfc.JFCLogParser; /** *

* This class defines JFC events. *

* * @author Steffen Herbold * @version 1.0 */ public class JFCEvent extends ReplayableEvent { /** *

* Id for object serialization. *

*/ private static final long serialVersionUID = 1L; /** *

* Internal map of parameters associated with the event. *

*/ private Map parameters; /** *

* Information about the event source. *

*/ private Map sourceParameters; /** *

* Information about the parent of the event source. *

*/ private Map parentParameters; /** *

* Constructor. Creates a new JFCEvent. *

* * @param type * type of the event */ public JFCEvent(String type) { super(type); parameters = new HashMap(); sourceParameters = new HashMap(); parentParameters = new HashMap(); } /** *

* Adds a new parameter to the event. *

* * @param name * name of the parameter * @param value * value of the parameter */ public void addParameter(String name, String value) { parameters.put(name, value); } /** *

* Retrieves the value of a parameter. *

* * @param name * name of the parameter * @return value of the parameter */ public String getParameter(String name) { return parameters.get(name); } /** *

* Adds new information about the source of the event. *

* * @param name * name of the information * @param value * value of the information */ public void addSourceInformation(String name, String value) { sourceParameters.put(name, value); } /** *

* Retrieves information about the source of the event. *

* * @param name * name of the information * @return value of the information */ public String getSourceInformation(String name) { return sourceParameters.get(name); } /** *

* Adds new information about the parent of the source of the event. *

* * @param name * name of the information * @param value * value of the information */ public void addParentInformation(String name, String value) { parentParameters.put(name, value); } /** *

* Used by the {@link JFCLogParser} to extend the target string of the * current event with a further ancestor. The resulting target string will * have the structure {@code etc.grandparent.parent.eventtarget}. *

* * @param extension * extension for the target. */ public void extendTarget(String extension) { if (target == null || "".equals(target)) { target = extension; } else { target += "." + extension; } } /** *

* Retrieves information about the parent of the source of the event. *

* * @param name * name of the information * @return value of the information */ public String getParentInformation(String name) { return parentParameters.get(name); } /** *

* This method implements the comparison between two targets of JFCEvents. * The targets are equal, if they have the same placement in the widget * hierarchy, i.e., the target strings describe the same widgets, according * to the implementation of widget equality provided by * {@link #compareWidgets(String, String)}. *

* * @see de.ugoe.cs.eventbench.data.Event#targetEquals(java.lang.String) */ @Override protected boolean targetEquals(String otherTarget) { return JFCTargetComparator.compare(target, otherTarget); } /** *

* The targetHashCode ignores the parts of the target that describe the * title and hash of a widget, to ensure that the equals/hashCode contract * is fulfilled. *

* * @see de.ugoe.cs.eventbench.data.Event#targetHashCode() */ @Override protected int targetHashCode() { int hashCode = 0; int multiplier = 29; if (target != null) { String[] targetParts = target.split("\\]\\.\\["); if (targetParts.length == 0) { hashCode = widgetHashCode(target); } else { for (String widgetString : targetParts) { hashCode = hashCode * multiplier + widgetHashCode(widgetString); } } } return hashCode; } /** *

* This method calculates the hashCode for a a widget. If is used by * {@link #targetHashCode()} to build the complete hashCode. *

* * @param widget * string describing the widget * @return hashCode of the widget */ private int widgetHashCode(String widget) { int hashCode = 0; int multiplier = 37; String[] widgetInfo = widget.split("','"); if (widgetInfo.length == 5) { hashCode = hashCode * multiplier + widgetInfo[1].hashCode(); hashCode = hashCode * multiplier + widgetInfo[2].hashCode(); hashCode = hashCode * multiplier + widgetInfo[3].hashCode(); } return hashCode; } }