Changeset 417


Ignore:
Timestamp:
04/03/12 10:59:23 (12 years ago)
Author:
sherbold
Message:
  • code documentation
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/jfc/data/JFCTargetComparator.java

    r404 r417  
    2323 */ 
    2424public 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         */ 
    2639        private static boolean mutable = true; 
    27          
     40 
     41        /** 
     42         * <p> 
     43         * Set of all currently known targets. 
     44         * </p> 
     45         */ 
    2846        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         */ 
    3054        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         */ 
    3265        public static void setMutable(boolean mutable) { 
    33                 if( JFCTargetComparator.mutable==true && mutable == false ) { 
     66                if (JFCTargetComparator.mutable == true && mutable == false) { 
    3467                        equalTargets = new HashMap<String, Set<String>>(); 
    35                         for( String target1 : knownTargets ) { 
     68                        for (String target1 : knownTargets) { 
    3669                                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)) { 
    3972                                                curEqualTargets.add(target2); 
    4073                                        } 
     
    69102        public static boolean compare(String target1, String target2) { 
    70103                boolean result = false; 
    71                 if( mutable ) { 
     104                if (mutable) { 
    72105                        instance.addTarget(target1); 
    73106                        instance.addTarget(target2); 
     
    76109                        JFCWidget widget1 = instance.find(target1); 
    77110                        JFCWidget widget2 = instance.find(target2); 
    78                         result = (widget1==widget2); 
    79                 } 
    80                  
    81                  
    82                 if( !mutable ) { 
     111                        result = (widget1 == widget2); 
     112                } 
     113 
     114                if (!mutable) { 
    83115                        Set<String> curEquals = equalTargets.get(target1); 
    84                         if( curEquals!=null ) { 
     116                        if (curEquals != null) { 
    85117                                result = curEquals.contains(target2); 
    86                         }                        
    87                 } 
    88                  
     118                        } 
     119                } 
     120 
    89121                return result; 
    90122        } 
     
    227259         * the known GUI hierarchy, by traversing the known widgets starting with 
    228260         * the {@link #rootWidgets}. 
     261         * </p> 
    229262         *  
    230263         * @param target 
     
    327360                 */ 
    328361                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; 
    331369 
    332370                /** 
     
    351389                        if (obj instanceof JFCWidget) { 
    352390                                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); 
    355395 
    356396                                boolean retVal; 
    357                                  
     397 
    358398                                if (widgetClass.equals("Class")) { 
    359399                                        retVal = (widgetClass.equals(other.widgetClass) 
     
    376416                @Override 
    377417                public int hashCode() { 
    378                         if( hashCode==0 ) { 
     418                        if (hashCode == 0) { 
    379419                                int multiplier = 7; 
    380420                                hashCode = multiplier * hashCode + widgetClass.hashCode(); 
Note: See TracChangeset for help on using the changeset viewer.