Changeset 380
- Timestamp:
- 02/01/12 13:46:11 (13 years ago)
- Location:
- trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/jfc/data
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/jfc/data/JFCEvent.java
r376 r380 173 173 @Override 174 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 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 */ 223 187 @Override 224 188 protected int targetHashCode() { 225 189 int hashCode = 0; 226 190 int multiplier = 29; 227 if ( target!=null) {228 String[] targetParts = target.split("\\ [\\.\\[");229 if ( targetParts.length==0) {191 if (target != null) { 192 String[] targetParts = target.split("\\]\\.\\["); 193 if (targetParts.length == 0) { 230 194 hashCode = widgetHashCode(target); 231 195 } else { 232 for( String widgetString : targetParts ) { 233 hashCode = hashCode * multiplier + widgetHashCode(widgetString); 196 for (String widgetString : targetParts) { 197 hashCode = hashCode * multiplier 198 + widgetHashCode(widgetString); 234 199 } 235 200 } 236 201 } 237 202 238 203 return hashCode; 239 204 } 240 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 */ 241 216 private int widgetHashCode(String widget) { 242 217 int hashCode = 0; 243 218 int multiplier = 37; 244 219 String[] widgetInfo = widget.split("','"); 245 if ( widgetInfo.length==5) {220 if (widgetInfo.length == 5) { 246 221 hashCode = hashCode * multiplier + widgetInfo[1].hashCode(); 247 222 hashCode = hashCode * multiplier + widgetInfo[2].hashCode();
Note: See TracChangeset
for help on using the changeset viewer.