Changeset 376 for trunk/EventBenchConsole/src/de/ugoe
- Timestamp:
- 01/31/12 12:00:06 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/jfc/data/JFCEvent.java
r359 r376 160 160 } 161 161 162 /* 163 * (non-Javadoc) 164 * 165 * @see de.ugoe.cs.eventbench.data.ReplayableEvent#equals(java.lang.Object) 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) 166 172 */ 167 173 @Override 168 public boolean equals(Object other) { 169 if (other == this) { 170 return true; 171 } 172 if (other instanceof JFCEvent) { 173 return super.equals(other) 174 && parameters.equals(((JFCEvent) other).parameters); 175 } 176 return false; 177 } 178 179 /* 180 * (non-Javadoc) 181 * 182 * @see de.ugoe.cs.eventbench.data.ReplayableEvent#hashCode() 183 */ 174 protected boolean targetEquals(String otherTarget) { 175 if( target==null || otherTarget==null ) { 176 return target==otherTarget; 177 } 178 String[] targetParts = target.split("\\]\\.\\["); 179 String[] otherParts = otherTarget.split("\\]\\.\\["); 180 if (targetParts.length != otherParts.length) { 181 return false; 182 } 183 184 boolean retVal; 185 if (targetParts.length == 0) { 186 retVal = compareWidgets(target, otherTarget); 187 } else { 188 retVal = true; 189 for (int i = 0; retVal && i < targetParts.length; i++) { 190 retVal &= compareWidgets(targetParts[i], otherParts[i]); 191 } 192 } 193 return retVal; 194 } 195 196 /** 197 * <p> 198 * Compares two widget strings of the form 199 * {@code ['title','class','index','text','hashCode']}. 200 * </p> 201 * 202 * @param widget1 203 * @param widget2 204 * @return 205 */ 206 private boolean compareWidgets(String widget1, String widget2) { 207 String[] widgetInfo1 = widget1.split("','"); 208 String[] widgetInfo2 = widget2.split("','"); 209 // ensure size is equal 210 if (widgetInfo1.length != 5 || widgetInfo2.length != 5) { 211 return false; 212 } 213 // ensure that class [1], index [2], and text [3] are equal 214 // and title [0] or hashCode [4] are equal 215 return (widgetInfo1[1].equals(widgetInfo2[1]) 216 && widgetInfo1[2].equals(widgetInfo2[2]) && widgetInfo1[3] 217 .equals(widgetInfo2[3])) 218 && (widgetInfo1[0].equals(widgetInfo2[0]) || widgetInfo1[4] 219 .equals(widgetInfo2[4])); 220 221 } 222 184 223 @Override 185 public int hashCode() { 186 int hashCode = super.hashCode(); 187 hashCode *= parameters.hashCode(); 224 protected int targetHashCode() { 225 int hashCode = 0; 226 int multiplier = 29; 227 if( target!=null ) { 228 String[] targetParts = target.split("\\[\\.\\["); 229 if( targetParts.length==0 ) { 230 hashCode = widgetHashCode(target); 231 } else { 232 for( String widgetString : targetParts ) { 233 hashCode = hashCode * multiplier + widgetHashCode(widgetString); 234 } 235 } 236 } 237 188 238 return hashCode; 189 239 } 240 241 private int widgetHashCode(String widget) { 242 int hashCode = 0; 243 int multiplier = 37; 244 String[] widgetInfo = widget.split("','"); 245 if( widgetInfo.length==5 ) { 246 hashCode = hashCode * multiplier + widgetInfo[1].hashCode(); 247 hashCode = hashCode * multiplier + widgetInfo[2].hashCode(); 248 hashCode = hashCode * multiplier + widgetInfo[3].hashCode(); 249 } 250 return hashCode; 251 } 190 252 191 253 }
Note: See TracChangeset
for help on using the changeset viewer.