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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.