Changeset 390


Ignore:
Timestamp:
02/20/12 11:54:55 (12 years ago)
Author:
sherbold
Message:
  • all hashValues are now only computed once, stored and only recomputed when something changes.
  • de.ugoe.cs.eventbench.jfc.data.JFCTargetComparator now allows precomputation of equalities
Location:
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/jfc/data
Files:
2 edited

Legend:

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

    r380 r390  
    4545         */ 
    4646        private Map<String, String> parentParameters; 
     47         
     48        private boolean targetChanged = false; 
     49         
     50        private int targetHash = -1; 
    4751 
    4852        /** 
     
    145149                        target += "." + extension; 
    146150                } 
     151                targetChanged = true; 
    147152        } 
    148153 
     
    187192        @Override 
    188193        protected int targetHashCode() { 
    189                 int hashCode = 0; 
    190                 int multiplier = 29; 
    191                 if (target != null) { 
    192                         String[] targetParts = target.split("\\]\\.\\["); 
    193                         if (targetParts.length == 0) { 
    194                                 hashCode = widgetHashCode(target); 
    195                         } else { 
    196                                 for (String widgetString : targetParts) { 
    197                                         hashCode = hashCode * multiplier 
    198                                                         + widgetHashCode(widgetString); 
     194                if( targetChanged || targetHash==-1 ) { 
     195                        targetHash = 0; 
     196                        int multiplier = 29; 
     197                        if (target != null) { 
     198                                String[] targetParts = target.split("\\]\\.\\["); 
     199                                if (targetParts.length == 0) { 
     200                                        targetHash = widgetHashCode(target); 
     201                                } else { 
     202                                        for (String widgetString : targetParts) { 
     203                                                targetHash = targetHash * multiplier 
     204                                                                + widgetHashCode(widgetString); 
     205                                        } 
    199206                                } 
    200207                        } 
     208                        targetChanged = false; 
    201209                } 
    202  
    203                 return hashCode; 
     210                return targetHash; 
    204211        } 
    205212 
     
    221228                        hashCode = hashCode * multiplier + widgetInfo[1].hashCode(); 
    222229                        hashCode = hashCode * multiplier + widgetInfo[2].hashCode(); 
    223                         hashCode = hashCode * multiplier + widgetInfo[3].hashCode(); 
     230                        //hashCode = hashCode * multiplier + widgetInfo[3].hashCode(); 
    224231                } 
    225232                return hashCode; 
  • trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/jfc/data/JFCTargetComparator.java

    r385 r390  
    22 
    33import java.util.ArrayList; 
     4import java.util.HashMap; 
     5import java.util.HashSet; 
    46import java.util.LinkedHashSet; 
    57import java.util.List; 
     8import java.util.Map; 
    69import java.util.Set; 
     10 
     11import org.apache.commons.collections15.CollectionUtils; 
    712 
    813/** 
     
    1823 */ 
    1924public 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        } 
    2047 
    2148        /** 
     
    4168         */ 
    4269        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; 
    5090        } 
    5191 
     
    287327                 */ 
    288328                String text; 
     329                 
     330                int hashCode=0; 
    289331 
    290332                /** 
     
    309351                        if (obj instanceof JFCWidget) { 
    310352                                JFCWidget other = (JFCWidget) obj; 
     353                                 
     354                                 
     355                                boolean titleEqual = CollectionUtils.containsAny(titles, other.titles); 
     356                                boolean hashEqual = CollectionUtils.containsAny(hashCodes, other.hashCodes); 
     357                                 
     358                                /* 
    311359                                Set<String> titlesCopy = new LinkedHashSet<String>(titles); 
    312360                                Set<String> hashCodesCopy = new LinkedHashSet<String>(hashCodes); 
    313361 
    314362                                titlesCopy.retainAll(other.titles); 
    315                                 hashCodesCopy.retainAll(other.hashCodes); 
     363                                hashCodesCopy.retainAll(other.hashCodes);*/ 
    316364 
    317365                                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                                /* 
    318376                                if (widgetClass.equals("Class")) { 
    319377                                        retVal = (widgetClass.equals(other.widgetClass) 
     
    325383                                                        && text.equals(other.text) && (!titlesCopy 
    326384                                                        .isEmpty() || !hashCodesCopy.isEmpty())); 
    327                                 } 
     385                                }*/ 
    328386                                return retVal; 
    329387                        } 
     
    338396                @Override 
    339397                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                        } 
    347406                        return hashCode; 
    348407                } 
Note: See TracChangeset for help on using the changeset viewer.