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* Information about the event source. *
*/ private Map* Information about the parent of the event source. *
*/ private Map* Constructor. Creates a new JFCEvent. *
* * @param type * type of the event */ public JFCEvent(String type) { super(type); parameters = 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) { if( target==null || otherTarget==null ) { return target==otherTarget; } String[] targetParts = target.split("\\]\\.\\["); String[] otherParts = otherTarget.split("\\]\\.\\["); if (targetParts.length != otherParts.length) { return false; } boolean retVal; if (targetParts.length == 0) { retVal = compareWidgets(target, otherTarget); } else { retVal = true; for (int i = 0; retVal && i < targetParts.length; i++) { retVal &= compareWidgets(targetParts[i], otherParts[i]); } } return retVal; } /** ** Compares two widget strings of the form * {@code ['title','class','index','text','hashCode']}. *
* * @param widget1 * @param widget2 * @return */ private boolean compareWidgets(String widget1, String widget2) { String[] widgetInfo1 = widget1.split("','"); String[] widgetInfo2 = widget2.split("','"); // ensure size is equal if (widgetInfo1.length != 5 || widgetInfo2.length != 5) { return false; } // ensure that class [1], index [2], and text [3] are equal // and title [0] or hashCode [4] are equal return (widgetInfo1[1].equals(widgetInfo2[1]) && widgetInfo1[2].equals(widgetInfo2[2]) && widgetInfo1[3] .equals(widgetInfo2[3])) && (widgetInfo1[0].equals(widgetInfo2[0]) || widgetInfo1[4] .equals(widgetInfo2[4])); } @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; } 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; } }