Changeset 413


Ignore:
Timestamp:
04/03/12 10:51:34 (12 years ago)
Author:
sherbold
Message:
  • changed equals method of de.ugoe.cs.eventbench.windows.data.WindowsEvent? to be able to better identify equal widgets throughout multiple sessions. To this aim, the class de.ugoe.cs.eventbench.windows.data.MFCTargetComparator has been introduced to compare the target strings of WindowsEvents?.
  • changed parseXML to set up the MFCTargetComparator
Location:
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/commands/CMDparseXML.java

    r297 r413  
    99import de.ugoe.cs.eventbench.data.GlobalDataContainer; 
    1010import de.ugoe.cs.eventbench.windows.MFCLogParser; 
     11import de.ugoe.cs.eventbench.windows.data.MFCTargetComparator; 
    1112import de.ugoe.cs.eventbench.windows.data.WindowTree; 
    1213import de.ugoe.cs.eventbench.windows.data.WindowsEvent; 
     
    6364 
    6465                Collection<List<WindowsEvent>> sequences = parser.getSequences(); 
     66                 
     67                Console.traceln("Pre-computing event target equalities."); 
     68                // compare all Events to a dummy event to make sure they are known by 
     69                // the MFCTargetComparator 
     70                WindowsEvent dummyEvent = new WindowsEvent("dummy"); 
     71                for (List<WindowsEvent> sequence : sequences) { 
     72                        for (WindowsEvent event : sequence) { 
     73                                event.equals(dummyEvent); 
     74                        } 
     75                } 
     76                MFCTargetComparator.setMutable(false); 
     77                 
    6578                SortedSet<String> targets = WindowTree.getInstance().getTargets(); 
    6679 
  • trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/data/WindowsEvent.java

    r198 r413  
    11package de.ugoe.cs.eventbench.windows.data; 
     2 
     3import java.io.ByteArrayInputStream; 
     4 
     5import javax.xml.parsers.DocumentBuilder; 
     6import javax.xml.parsers.DocumentBuilderFactory; 
     7 
     8import org.w3c.dom.Document; 
     9import org.w3c.dom.Element; 
     10import org.w3c.dom.NodeList; 
    211 
    312import de.ugoe.cs.eventbench.data.ReplayableEvent; 
     
    3342        } 
    3443 
     44        @Override 
     45        protected boolean targetEquals(String otherTarget) { 
     46                return MFCTargetComparator.compare(target, otherTarget); 
     47        } 
     48         
     49        int targetHash = 0; 
     50         
     51        @Override 
     52        protected int targetHashCode() { 
     53                if( targetHash==0 ) { 
     54                        int multiplier = 17; 
     55                        if (target != null) { 
     56                                Document doc; 
     57                                try { 
     58                                        DocumentBuilder documentBuilder = DocumentBuilderFactory 
     59                                                        .newInstance().newDocumentBuilder(); 
     60                                        doc = documentBuilder.parse(new ByteArrayInputStream( 
     61                                                        ("<dummy>" + target + "</dummy>").getBytes("UTF-8"))); 
     62                                } catch (Exception e) { 
     63                                        e.printStackTrace(); 
     64                                        return 0; 
     65                                } 
     66                                doc.getDocumentElement().normalize(); 
     67                                NodeList widgets = doc.getElementsByTagName("window"); 
     68 
     69                                for (int i = 0; i < widgets.getLength(); i++) { 
     70                                        Element currentWidget = (Element) widgets.item(i); 
     71                                        targetHash = targetHash* multiplier + widgetHashCode(currentWidget); 
     72                                } 
     73                        } 
     74                } 
     75                return targetHash; 
     76        } 
     77         
     78        private int widgetHashCode(Element currentWidget) { 
     79                int hashCode = 0; 
     80                int multiplier = 41; 
     81                hashCode = hashCode * multiplier + currentWidget.getAttribute("class").hashCode(); 
     82                hashCode = hashCode * multiplier + currentWidget.getAttribute("resourceId").hashCode(); 
     83                hashCode = hashCode * multiplier + currentWidget.getAttribute("isModal").hashCode(); 
     84                return hashCode; 
     85        } 
    3586} 
Note: See TracChangeset for help on using the changeset viewer.