Changeset 417 for trunk/EventBenchConsole/src/de
- Timestamp:
- 04/03/12 10:59:23 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/jfc/data/JFCTargetComparator.java
r404 r417 23 23 */ 24 24 public class JFCTargetComparator { 25 25 26 /** 27 * <p> 28 * If mutable is true, new target strings can be added to the internal 29 * memory. This leads to a very expensive {@link #compare(String, String)} 30 * operation. 31 * </p> 32 * <p> 33 * if mutable is set to false, currently possible equal targets are 34 * pre-computed. This pre-computation is expensive and might take a while. 35 * In turn, the {@link #compare(String, String)} operation becomes very 36 * cheap. 37 * </p> 38 */ 26 39 private static boolean mutable = true; 27 40 41 /** 42 * <p> 43 * Set of all currently known targets. 44 * </p> 45 */ 28 46 private static Set<String> knownTargets = new LinkedHashSet<String>(); 29 47 48 /** 49 * <p> 50 * Map that contains for all known target strings all equal target strings. 51 * Pre-computed when {@link #mutable} is set to false. 52 * </p> 53 */ 30 54 private static Map<String, Set<String>> equalTargets; 31 55 56 /** 57 * <p> 58 * Changes the mutability of the comparator. If the mutability is changed 59 * from true to false, the map {@link #equalTargets} is computed. 60 * </p> 61 * 62 * @param mutable 63 * new mutability of the comparator 64 */ 32 65 public static void setMutable(boolean mutable) { 33 if ( JFCTargetComparator.mutable==true && mutable == false) {66 if (JFCTargetComparator.mutable == true && mutable == false) { 34 67 equalTargets = new HashMap<String, Set<String>>(); 35 for ( String target1 : knownTargets) {68 for (String target1 : knownTargets) { 36 69 Set<String> curEqualTargets = new HashSet<String>(); 37 for ( String target2 : knownTargets) {38 if ( compare(target1, target2)) {70 for (String target2 : knownTargets) { 71 if (compare(target1, target2)) { 39 72 curEqualTargets.add(target2); 40 73 } … … 69 102 public static boolean compare(String target1, String target2) { 70 103 boolean result = false; 71 if ( mutable) {104 if (mutable) { 72 105 instance.addTarget(target1); 73 106 instance.addTarget(target2); … … 76 109 JFCWidget widget1 = instance.find(target1); 77 110 JFCWidget widget2 = instance.find(target2); 78 result = (widget1==widget2); 79 } 80 81 82 if( !mutable ) { 111 result = (widget1 == widget2); 112 } 113 114 if (!mutable) { 83 115 Set<String> curEquals = equalTargets.get(target1); 84 if ( curEquals!=null) {116 if (curEquals != null) { 85 117 result = curEquals.contains(target2); 86 } 87 } 88 118 } 119 } 120 89 121 return result; 90 122 } … … 227 259 * the known GUI hierarchy, by traversing the known widgets starting with 228 260 * the {@link #rootWidgets}. 261 * </p> 229 262 * 230 263 * @param target … … 327 360 */ 328 361 String text; 329 330 int hashCode=0; 362 363 /** 364 * <p> 365 * Pre-computed hash code of the widget. 366 * </p> 367 */ 368 int hashCode = 0; 331 369 332 370 /** … … 351 389 if (obj instanceof JFCWidget) { 352 390 JFCWidget other = (JFCWidget) obj; 353 boolean titleEqual = CollectionUtils.containsAny(titles, other.titles); 354 boolean hashEqual = CollectionUtils.containsAny(hashCodes, other.hashCodes); 391 boolean titleEqual = CollectionUtils.containsAny(titles, 392 other.titles); 393 boolean hashEqual = CollectionUtils.containsAny(hashCodes, 394 other.hashCodes); 355 395 356 396 boolean retVal; 357 397 358 398 if (widgetClass.equals("Class")) { 359 399 retVal = (widgetClass.equals(other.widgetClass) … … 376 416 @Override 377 417 public int hashCode() { 378 if ( hashCode==0) {418 if (hashCode == 0) { 379 419 int multiplier = 7; 380 420 hashCode = multiplier * hashCode + widgetClass.hashCode();
Note: See TracChangeset
for help on using the changeset viewer.