Changeset 390 for trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/jfc/data/JFCTargetComparator.java
- Timestamp:
- 02/20/12 11:54:55 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/jfc/data/JFCTargetComparator.java
r385 r390 2 2 3 3 import java.util.ArrayList; 4 import java.util.HashMap; 5 import java.util.HashSet; 4 6 import java.util.LinkedHashSet; 5 7 import java.util.List; 8 import java.util.Map; 6 9 import java.util.Set; 10 11 import org.apache.commons.collections15.CollectionUtils; 7 12 8 13 /** … … 18 23 */ 19 24 public class JFCTargetComparator { 25 26 private static boolean mutable = true; 27 28 private static Set<String> knownTargets = new LinkedHashSet<String>(); 29 30 private static Map<String, Set<String>> equalTargets; 31 32 public static void setMutable(boolean mutable) { 33 if( JFCTargetComparator.mutable==true && mutable == false ) { 34 equalTargets = new HashMap<String, Set<String>>(); 35 for( String target1 : knownTargets ) { 36 Set<String> curEqualTargets = new HashSet<String>(); 37 for( String target2 : knownTargets ) { 38 if( compare(target1, target2) ) { 39 curEqualTargets.add(target2); 40 } 41 } 42 equalTargets.put(target1, curEqualTargets); 43 } 44 } 45 JFCTargetComparator.mutable = mutable; 46 } 20 47 21 48 /** … … 41 68 */ 42 69 public static boolean compare(String target1, String target2) { 43 instance.addTarget(target1); 44 instance.addTarget(target2); 45 46 JFCWidget widget1 = instance.find(target1); 47 JFCWidget widget2 = instance.find(target2); 48 49 return widget1 == widget2; 70 boolean result = false; 71 if( mutable ) { 72 instance.addTarget(target1); 73 instance.addTarget(target2); 74 knownTargets.add(target1); 75 knownTargets.add(target2); 76 JFCWidget widget1 = instance.find(target1); 77 JFCWidget widget2 = instance.find(target2); 78 result = (widget1==widget2); 79 } 80 81 82 if( !mutable ) { 83 Set<String> curEquals = equalTargets.get(target1); 84 if( curEquals!=null ) { 85 result = curEquals.contains(target2); 86 } 87 } 88 89 return result; 50 90 } 51 91 … … 287 327 */ 288 328 String text; 329 330 int hashCode=0; 289 331 290 332 /** … … 309 351 if (obj instanceof JFCWidget) { 310 352 JFCWidget other = (JFCWidget) obj; 353 354 355 boolean titleEqual = CollectionUtils.containsAny(titles, other.titles); 356 boolean hashEqual = CollectionUtils.containsAny(hashCodes, other.hashCodes); 357 358 /* 311 359 Set<String> titlesCopy = new LinkedHashSet<String>(titles); 312 360 Set<String> hashCodesCopy = new LinkedHashSet<String>(hashCodes); 313 361 314 362 titlesCopy.retainAll(other.titles); 315 hashCodesCopy.retainAll(other.hashCodes); 363 hashCodesCopy.retainAll(other.hashCodes);*/ 316 364 317 365 boolean retVal; 366 367 if (widgetClass.equals("Class")) { 368 retVal = (widgetClass.equals(other.widgetClass) 369 && text.equals(other.text) && (titleEqual || hashEqual)); 370 } else { 371 retVal = (widgetClass.equals(other.widgetClass) 372 && index.equals(other.index) 373 && text.equals(other.text) && (titleEqual || hashEqual)); 374 } 375 /* 318 376 if (widgetClass.equals("Class")) { 319 377 retVal = (widgetClass.equals(other.widgetClass) … … 325 383 && text.equals(other.text) && (!titlesCopy 326 384 .isEmpty() || !hashCodesCopy.isEmpty())); 327 } 385 }*/ 328 386 return retVal; 329 387 } … … 338 396 @Override 339 397 public int hashCode() { 340 int multiplier = 7; 341 int hashCode = 0; 342 hashCode = multiplier * hashCode + widgetClass.hashCode(); 343 if (!widgetClass.equals("Class")) { 344 hashCode = multiplier * hashCode + index.hashCode(); 345 } 346 hashCode = multiplier * hashCode + text.hashCode(); 398 if( hashCode==0 ) { 399 int multiplier = 7; 400 hashCode = multiplier * hashCode + widgetClass.hashCode(); 401 if (!widgetClass.equals("Class")) { 402 hashCode = multiplier * hashCode + index.hashCode(); 403 } 404 hashCode = multiplier * hashCode + text.hashCode(); 405 } 347 406 return hashCode; 348 407 }
Note: See TracChangeset
for help on using the changeset viewer.