Changeset 1436 for trunk


Ignore:
Timestamp:
03/06/14 10:30:03 (10 years ago)
Author:
pharms
Message:
  • corrected a bug in creating hashcodes for GUI elements (they changed after storing a GUI model to a file and then reloading it)
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-events-test/src/test/java/de/ugoe/cs/autoquest/eventcore/guimodel/AbstractDefaultGUIElementTest.java

    r1396 r1436  
    6969                assertFalse(guiElements[i].equals(guiElements[j])); 
    7070                assertFalse(guiElements[j].equals(guiElements[i])); 
    71                 assertNotSame(guiElements[i].hashCode(), guiElements[j].hashCode()); 
    7271            } 
    7372        } 
  • trunk/autoquest-core-events/src/main/java/de/ugoe/cs/autoquest/eventcore/guimodel/AbstractDefaultGUIElement.java

    r1433 r1436  
    6969     */ 
    7070    private GUIModel guiModel; 
     71     
     72    /** 
     73     * <p> 
     74     * the hash code of this object 
     75     * </p> 
     76     */ 
     77    private int hashCode; 
    7178 
    7279    /** 
     
    8491        this.usageObserved = false; 
    8592        setParent(parent); 
     93         
     94        if (specification != null) { 
     95            this.hashCode = specification.hashCode(); 
     96        } 
     97        else { 
     98            this.hashCode = 0; 
     99        } 
    86100    } 
    87101 
     
    135149                    this.equalGUIElements.add(other); 
    136150                    other.equalGUIElements = this.equalGUIElements; 
     151                    other.hashCode = this.hashCode; 
    137152                } 
    138153                else { 
    139154                    addIfNotContained(other.equalGUIElements, this); 
    140155                    this.equalGUIElements = other.equalGUIElements; 
     156                    this.hashCode = other.hashCode; 
    141157                } 
    142158            } 
     
    145161                    addIfNotContained(this.equalGUIElements, other); 
    146162                    other.equalGUIElements = this.equalGUIElements; 
     163                    other.hashCode = this.hashCode; 
    147164                } 
    148165                else if (this.equalGUIElements != other.equalGUIElements) { 
     
    153170                    for (AbstractDefaultGUIElement candidate : other.equalGUIElements) { 
    154171                        candidate.equalGUIElements = this.equalGUIElements; 
     172                        candidate.hashCode = this.hashCode; 
    155173                    } 
    156174 
    157175                    other.equalGUIElements = this.equalGUIElements; 
     176                    other.hashCode = this.hashCode; 
    158177                } 
    159178                // else 
     
    219238        // implement final, as GUI elements are all singletons and they equal only if they are the 
    220239        // same object. If there are several GUI element objects that represent the same GUI element 
    221         // then they are stored in the list of equal elements. In this case, the hash code of the 
    222         // list is unique within the system 
    223         synchronized (AbstractDefaultGUIElement.class) { 
    224             if (this.equalGUIElements == null) { 
    225                 this.equalGUIElements = new LinkedList<AbstractDefaultGUIElement>(); 
    226                 this.equalGUIElements.add(this); 
    227             } 
    228              
    229             return System.identityHashCode(this.equalGUIElements); 
    230         } 
     240        // then they are stored in the list of equal elements. But at least their type is expected 
     241        // to be equal, so return the hash code of the type. 
     242        return hashCode; 
    231243    } 
    232244     
  • trunk/autoquest-core-events/src/main/java/de/ugoe/cs/autoquest/eventcore/guimodel/GUIModel.java

    r1433 r1436  
    167167                    result.add(child.guiElement); 
    168168                } 
     169            } 
     170        } 
     171        else { 
     172            System.out.println("problem"); 
     173            boolean found = false; 
     174            for (Map.Entry<IGUIElement, TreeNode> entry : allNodes.entrySet()) { 
     175                if (entry.getKey().equals(guiElement)) { 
     176                    if (!found) { 
     177                        System.out.println(guiElement.hashCode() + "  " + entry.getKey().hashCode()); 
     178                        found = true; 
     179                    } 
     180                    else { 
     181                        Console.traceln(Level.SEVERE, "Multiple nodes in the internal GUI model " + 
     182                                        "match the same GUI element. This should not be the case " + 
     183                                        "and the GUI model is probably invalid."); 
     184                    } 
     185                } 
     186            } 
     187             
     188            if (!found) { 
     189                Console.traceln(Level.SEVERE, "GUI element belonging to model not found in model"); 
    169190            } 
    170191        } 
     
    322343         
    323344        TreeNode parent = findNode(guiElements.get(0).getParent()); 
     345        if (parent == null) { 
     346            throw new IllegalArgumentException("GUI elements to group must have a parent: parent " + 
     347                                               "of " + guiElements.get(0) + " is " + 
     348                                               guiElements.get(0).getParent() + " and not found " + 
     349                                               "in the model"); 
     350        } 
    324351         
    325352        List<TreeNode> nodesToGroup = new LinkedList<TreeNode>(); 
     
    450477 
    451478        if (node1 == null || node2 == null) { 
    452             throw new IllegalArgumentException( 
    453                                                "Error while merging nodes: one element is not part of the GUI model!"); 
     479            throw new IllegalArgumentException 
     480                ("Error while merging nodes: one element is not part of the GUI model!"); 
    454481        } 
    455482 
     
    645672         
    646673        allNodes.put(replacement.guiElement, replacement); 
    647  
     674         
    648675        return replacement; 
    649676    } 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLDocumentSpec.java

    r1276 r1436  
    7777     */ 
    7878    public HTMLDocumentSpec(HTMLServerSpec server, String path, String query, String title) { 
    79         super("document"); 
     79        super("document", (server != null ? server.hashCode() : 0) + 
     80              (path != null ? path.hashCode() : 0) + (query != null ? query.hashCode() : 0) + 
     81              (title != null ? title.hashCode() : 0)); 
    8082         
    8183        if (server == null) { 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLGUIElementSpec.java

    r1276 r1436  
    4040     */ 
    4141    private String type; 
     42 
     43    /** 
     44     * <p> 
     45     * the hashCode of this GUI element specification 
     46     * </p> 
     47     */ 
     48    private int hashCode; 
    4249     
    4350    /** 
     
    5057     * @throws IllegalArgumentException if the provided type is null 
    5158     */ 
    52     public HTMLGUIElementSpec(String type) { 
     59    public HTMLGUIElementSpec(String type, int hashCode) { 
    5360        if (type == null) { 
    5461            throw new IllegalArgumentException("type must not be null"); 
     
    5663 
    5764        this.type = type; 
     65        this.hashCode = hashCode; 
    5866    } 
    5967 
     
    8795    } 
    8896 
     97    /* (non-Javadoc) 
     98     * @see java.lang.Object#hashCode() 
     99     */ 
     100    @Override 
     101    public int hashCode() { 
     102        return hashCode; 
     103    } 
     104 
    89105} 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageElementSpec.java

    r1276 r1436  
    8383     */ 
    8484    public HTMLPageElementSpec(HTMLDocumentSpec page, String tagName, String htmlId, int index) { 
    85         super(tagName); 
     85        super(tagName, (page != null ? page.hashCode() : 0) + 
     86              (tagName != null ? tagName.hashCode() : 0) +  
     87              (htmlId != null ? htmlId.hashCode() : 0) + (index >= 0 ? index : 0)); 
    8688         
    8789        if (page == null) { 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLServerSpec.java

    r1276 r1436  
    5959     */ 
    6060    public HTMLServerSpec(String host, int port) { 
    61         super("server"); 
     61        super("server", (host != null ? host.hashCode() : 0) + port); 
    6262         
    6363        if (host == null) { 
Note: See TracChangeset for help on using the changeset viewer.