Changeset 1089


Ignore:
Timestamp:
02/19/13 09:41:27 (12 years ago)
Author:
pharms
Message:
  • prevent logging of the same GUI elements several times
  • improved efficiency of hash code calculation
  • improved efficiency of reuse of GUI elements
Location:
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlDocument.java

    r1075 r1089  
    4545     
    4646    /** 
     47     * the hash code of this document 
     48     */ 
     49    private int hashCode; 
     50     
     51    /** 
    4752     * <p> 
    4853     * instantiates a new document element 
     
    7479            this.query = "?" + this.query; 
    7580        } 
     81         
     82        this.hashCode = this.server.hashCode() + this.path.hashCode() + 
     83            (this.query != null ? this.query.hashCode() : 0) + 
     84            (this.title != null ? this.title.hashCode() : 0); 
    7685    } 
    7786 
     
    138147    @Override 
    139148    public int hashCode() { 
    140         return server.hashCode() + path.hashCode() + (query != null ? query.hashCode() : 0) + 
    141             (title != null ? title.hashCode() : 0); 
     149        return hashCode; 
    142150    } 
    143151 
  • trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorOutputWriter.java

    r1069 r1089  
    2121import java.io.PrintWriter; 
    2222import java.text.DecimalFormat; 
     23import java.util.HashSet; 
     24import java.util.Set; 
    2325 
    2426import de.ugoe.cs.util.StringTools; 
     
    6264 
    6365    /** 
    64      * the is of the client of which all messages are logged through this writer 
     66     * the id of the client of which all messages are logged through this writer 
    6567     */ 
    6668    private String clientId; 
     
    8082     */ 
    8183    private long lastUpdate; 
     84     
     85    /** 
     86     * the GUI elements, that were already logged and need therefore not be logged again into 
     87     * the same file 
     88     */ 
     89    private Set<HtmlGUIElement> loggedGUIElements = new HashSet<HtmlGUIElement>(); 
    8290 
    8391    /** 
     
    215223     */ 
    216224    private void dumpGuiStructure(HtmlGUIElement guiStructure) { 
    217         outputWriter.print("<component id=\""); 
    218         outputWriter.print(guiStructure.getId()); 
    219         outputWriter.println("\">"); 
    220          
    221         if (guiStructure instanceof HtmlServer) { 
    222             dumpParam("host", ((HtmlServer) guiStructure).getName()); 
    223             dumpParam("port", ((HtmlServer) guiStructure).getPort()); 
    224         } 
    225         else if (guiStructure instanceof HtmlDocument) { 
    226             dumpParam("path", ((HtmlDocument) guiStructure).getPath()); 
    227             dumpParam("query", ((HtmlDocument) guiStructure).getQuery()); 
    228             dumpParam("title", ((HtmlDocument) guiStructure).getTitle()); 
    229         } 
    230         else if (guiStructure instanceof HtmlPageElement) { 
    231             dumpParam("tagname", ((HtmlPageElement) guiStructure).getTagName()); 
    232             dumpParam("htmlid", ((HtmlPageElement) guiStructure).getHtmlId()); 
    233             dumpParam("index", ((HtmlPageElement) guiStructure).getIndex()); 
    234         } 
    235          
    236         dumpParam("parent", guiStructure.getParentId()); 
    237          
    238         outputWriter.println("</component>"); 
     225        if (!loggedGUIElements.contains(guiStructure)) { 
     226            outputWriter.print("<component id=\""); 
     227            outputWriter.print(guiStructure.getId()); 
     228            outputWriter.println("\">"); 
     229         
     230            if (guiStructure instanceof HtmlServer) { 
     231                dumpParam("host", ((HtmlServer) guiStructure).getName()); 
     232                dumpParam("port", ((HtmlServer) guiStructure).getPort()); 
     233            } 
     234            else if (guiStructure instanceof HtmlDocument) { 
     235                dumpParam("path", ((HtmlDocument) guiStructure).getPath()); 
     236                dumpParam("query", ((HtmlDocument) guiStructure).getQuery()); 
     237                dumpParam("title", ((HtmlDocument) guiStructure).getTitle()); 
     238            } 
     239            else if (guiStructure instanceof HtmlPageElement) { 
     240                dumpParam("tagname", ((HtmlPageElement) guiStructure).getTagName()); 
     241                dumpParam("htmlid", ((HtmlPageElement) guiStructure).getHtmlId()); 
     242                dumpParam("index", ((HtmlPageElement) guiStructure).getIndex()); 
     243            } 
     244             
     245            dumpParam("parent", guiStructure.getParentId()); 
     246         
     247            outputWriter.println("</component>"); 
     248         
     249            loggedGUIElements.add(guiStructure); 
     250        } 
    239251         
    240252        if (guiStructure.getChildren() != null) { 
     
    369381        outputWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 
    370382        outputWriter.println("<session>"); 
     383         
     384        loggedGUIElements.clear(); 
    371385    } 
    372386 
  • trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlPageElement.java

    r1075 r1089  
    5151     
    5252    /** 
     53     * the hash code of this document 
     54     */ 
     55    private int hashCode; 
     56     
     57    /** 
    5358     * <p> 
    5459     * instantiates a new element representing a tag in an HTML page 
     
    8994        this.htmlId = htmlId; 
    9095        this.index = index; 
     96         
     97        this.hashCode = this.document.hashCode() + this.tagName.hashCode() + 
     98            (this.parent != null ? this.parent.hashCode() : 0) + 
     99            (this.htmlId != null ? this.htmlId.hashCode() : 0) + 
     100            (this.index != null ? this.index : 0); 
    91101    } 
    92102 
     
    203213    @Override 
    204214    public int hashCode() { 
    205         return document.hashCode() + tagName.hashCode() + (parent != null ? parent.hashCode() : 0) + 
    206             (htmlId != null ? htmlId.hashCode() : 0) + (index != null ? index : 0); 
     215        return hashCode; 
    207216    } 
    208217 
  • trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlServer.java

    r1075 r1089  
    3535     
    3636    /** 
     37     * the hash code of this document 
     38     */ 
     39    private int hashCode; 
     40     
     41    /** 
    3742     * <p> 
    3843     * instantiates a new server element 
     
    5762        } 
    5863 
     64        this.hashCode = this.name.hashCode() + this.port; 
    5965    } 
    6066 
     
    113119    @Override 
    114120    public int hashCode() { 
    115         return name.hashCode() + port; 
     121        return hashCode; 
    116122    } 
    117123 
Note: See TracChangeset for help on using the changeset viewer.