Index: trunk/autoquest-plugin-android/src/main/java/de/ugoe/cs/autoquest/plugin/android/guimodel/ANDROIDGUIElementSpec.java
===================================================================
--- trunk/autoquest-plugin-android/src/main/java/de/ugoe/cs/autoquest/plugin/android/guimodel/ANDROIDGUIElementSpec.java	(revision 1819)
+++ trunk/autoquest-plugin-android/src/main/java/de/ugoe/cs/autoquest/plugin/android/guimodel/ANDROIDGUIElementSpec.java	(revision 1869)
@@ -31,5 +31,5 @@
     /**
      * <p>
-     * default serial version UID
+     * Default serial version UID
      * </p>
      */
@@ -37,5 +37,7 @@
 
     /*
-     * (non-Javadoc) see de.ugoe.cs.autoquest.androidmonitor.AndroidmonitorLogFile#logComponent()
+     * (non-Javadoc)
+     * 
+     * @see de.ugoe.cs.autoquest.androidmonitor.AndroidmonitorLogFile#logComponent()
      */
     /**
@@ -46,5 +48,5 @@
      * </p>
      */
-    private int hashCode;
+    private int elementHash;
 
     /**
@@ -56,7 +58,12 @@
     private String path;
 
-    /**
-     * <p>
-     * id of the object as it is returned by view.getId()
+    /*
+     * (non-Javadoc)
+     * 
+     * @see http://developer.android.com/reference/android/view/View.html#getId()
+     */
+    /**
+     * <p>
+     * Id of the object as it is returned by view.getId().
      * </p>
      */
@@ -65,6 +72,12 @@
     /**
      * <p>
-     * the type of GUI element represented by this specification, which is usually the java class of
-     * the android GUI element
+     * Current name of the GUI element
+     * </p>
+     */
+    private String name;
+
+    /**
+     * <p>
+     * The type of GUI element, i.e., the class of the android GUI element.
      * </p>
      */
@@ -73,8 +86,61 @@
     /**
      * <p>
-     * Type hierarchy of the class itself
+     * Type hierarchy of the class itself.
      * </p>
      */
     private List<String> typeHierarchy = null;
+    
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSecificationSimilarity(IGUIElementSpec
+     * )
+     */
+    @Override
+    public boolean getSimilarity(IGUIElementSpec other) {
+        if (this == other) {
+            return true;
+        }
+
+        if (!(other instanceof ANDROIDGUIElementSpec)) {
+            return false;
+        }
+
+        ANDROIDGUIElementSpec otherSpec = (ANDROIDGUIElementSpec) other;
+
+        if (type == null ? otherSpec.type != null : !type.equals(otherSpec.type)) {
+            return false;
+        }
+
+        /*
+         * Up to now, we compared, if the basics match. Due to testing with different virtual
+         * devices it seems to be the case that the id of a view (named index here) keeps the same
+         * even on different devices even if the hashCode changes. Some of the GUI elements does not
+         * have an id (id is -1).
+         */
+
+        if (otherSpec.index > 1 && index == otherSpec.index) {
+            return true;
+        }
+
+        /*
+         * Two elements could also be similar if the path of the elements is equal and the name is
+         * set, equal and not equal to "image:" even if index <= 1. This comparison is not
+         * implemented up to know due to the reason that all recorded elements up to 2015/01 either
+         * have an index > 1 or no name to be compared.
+         * 
+         * In all other cases up to know it is not clear if two elements are similar.
+         * 
+         * Not working:
+         * 
+         * - Position of the elements: Due to the reason that there are a lot of different displays
+         * on the android market and the in the most cases the layout depends on the display size
+         * (different resolutions) similar elements have different positions.
+         */
+
+        return false;
+    }
+    
 
     /*
@@ -102,7 +168,126 @@
             return typeHierarchy.toArray(new String[typeHierarchy.size()]);
     }
-
-    @Override
-    public boolean getSimilarity(IGUIElementSpec other) {
+    
+    /**
+     * <p>
+     * Returns the object hash of the specified GUI element.
+     * </p>
+     * 
+     * @return the elementHash
+     */
+    public int getElementHash() {
+        return elementHash;
+    }
+
+    /**
+     * <p>
+     * Returns the path associated with the specified GUI element.
+     * </p>
+     * 
+     * @return the path to an element
+     */
+    public String getPath() {
+        return path;
+    }
+
+    /**
+     * <p>
+     * Returns the GUI element identifier.
+     * </p>
+     * 
+     * @return identifier of the GUI element
+     */
+    public int getIndex() {
+        return index;
+    }
+
+    /**
+     * <p>
+     * Returns the name of the specified GUI element. Displayed text in the application or image
+     * name.
+     * </p>
+     * 
+     * @return text or image of the GUI element.
+     */
+    public String getName() {        
+        if (name == null || name.trim().length() == 0) {
+            return "NOT_SET";
+        }
+        return name;
+    }
+
+    /**
+     * <p>
+     * Sets the GUI element identifier.
+     * </p>
+     * 
+     * @param indentifier
+     */
+    public void setIndex(int index) {
+        this.index = index;
+    }
+
+    /**
+     * Set the hash code associated with the GUI element.
+     * 
+     * @param hash
+     *            the hash of an element object
+     */
+    public void setElementHash(int hash) {
+        this.elementHash = hash;
+    }
+
+    /**
+     * Set the path associated with the specified GUI element.
+     * 
+     * @param path
+     *            the path to an element
+     */
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    /**
+     * <p>
+     * Sets the type of the specified GUI element.
+     * </p>
+     * 
+     * @param type
+     *            the type
+     */
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    /**
+     * <p>
+     * Sets the name of the specified GUI element. Displayed text in the application or image name.
+     * </p>
+     * 
+     * @param name
+     *            the name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * <p>
+     * Sets the type hierarchy of the specified GUI element.
+     * 
+     * @param typeHierarchy
+     *            </p>
+     */
+    public void setTypeHierarchy(List<String> typeHierarchy) {
+        this.typeHierarchy = typeHierarchy;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * 
+     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#equals(IGUIElementSpec)
+     */
+    @Override
+    public boolean equals(Object other) {
         if (this == other) {
             return true;
@@ -113,86 +298,34 @@
         }
 
-        // Check wheter view.id() keeps the same even if something in the
-        // structure changes. The hash in the JFCMonitor seems to be unique at
-        // all. In the Androidmonitore the hash of an element changes even from
-        // one start of the activity to another.
+        ANDROIDGUIElementSpec otherSpec = (ANDROIDGUIElementSpec) other;
+
+        return (elementHash == otherSpec.elementHash) &&
+            (path == null ? otherSpec.path == null : path.equals(otherSpec.path)) &&
+            (index == otherSpec.index) &&
+            (name == null ? otherSpec.name == null : name.equals(otherSpec.name)) &&
+            (type == null ? otherSpec.type == null : type.equals(otherSpec.type));
+    }
+    
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+     // 17 due to the reason that this is a prime number.
+        int result = 17;
         /*
-         * Maybe some other comparisons will be necessary in the future.
+         * 31 due to the reason that a lot of VM's could optimize this multiplication by a shift.
+         * Source: Effective Java, Joshua Bloch, 2008, p.48
          */
-
-        return false;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see java.lang.Object#hashCode()
-     */
-    @Override
-    public int hashCode() {
-        return hashCode;
-    }
-
-    /**
-     * <p>
-     * Returns the path associated with the specified GUI element.
-     * </p>
-     * 
-     * @return the path to an element
-     */
-    public String getPath() {
-        return path;
-    }
-
-    public int getIndex() {
-        return index;
-    }
-
-    public void setIndex(int index) {
-        this.index = index;
-    }
-
-    /**
-     * Set the hash code associated with the GUI element.
-     * 
-     * @param hash
-     *            the hash of an element object
-     */
-    public void setHashCode(int hash) {
-        this.hashCode = hash;
-    }
-
-    /**
-     * Set the path associated with the specified GUI element.
-     * 
-     * @param path
-     *            the path to an element
-     */
-    public void setPath(String path) {
-        this.path = path;
-    }
-
-    /**
-     * <p>
-     * Sets the type of the specified GUI element.
-     * </p>
-     * 
-     * @param type
-     *            the type
-     */
-    public void setType(String type) {
-        this.type = type;
-    }
-
-    /**
-     * <p>
-     * Sets the type hierarchy of the specified GUI element.
-     * 
-     * @param typeHierarchy
-     *            </p>
-     */
-    public void setTypeHierarchy(List<String> typeHierarchy) {
-        this.typeHierarchy = typeHierarchy;
-    }
+        result = 31 * result + elementHash;
+        result = 31 * result + path.hashCode();
+        result = 31 * result + index;
+        result = 31 * result + getName().hashCode();
+        result = 31 * result + type.hashCode();     
+        return result;
+    }
+    
 
 }
