source: trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElementSpec.java @ 589

Last change on this file since 589 was 589, checked in by sherbold, 12 years ago
  • started changing the similarity structure of the GUI model. The equality is now absolute (i.e., boolean instead of an int indicating the degree). Also, lists of equally observed name/hash combinations are now stored. There still seem to be mistakes, however, the structural changes to the interfaces warrant a commit.
File size: 4.2 KB
Line 
1// Module    : $RCSfile: JFCHGUIElementSpec.java,v $
2// Version   : $Revision: 0.0 $  $Author: pharms $  $Date: 17.08.2012 $
3// Project   : quest-plugin-jfc
4// Creation  : 2012 by pharms
5// Copyright : Patrick Harms, 2012
6package de.ugoe.cs.quest.plugin.jfc.guimodel;
7
8import java.util.LinkedList;
9import java.util.List;
10
11import org.apache.commons.collections15.CollectionUtils;
12
13import de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec;
14
15/**
16 * <p>
17 * TODO comment
18 * </p>
19 *
20 * @version $Revision: $ $Date: 17.08.2012$
21 * @author 2012, last modified by $Author: pharms$
22 */
23public class JFCGUIElementSpec implements IGUIElementSpec {
24
25    /** */
26    private List<String> name = new LinkedList<String>();
27   
28    /** */
29    private String type = null;
30   
31    /** */
32    private String icon = null;
33   
34    /** */
35    private int index = -1;
36   
37    /** */
38    private List<String> elementHash = new LinkedList<String>();
39   
40    /* (non-Javadoc)
41     * @see de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#getSecificationSimilarity(IGUIElementSpec)
42     */
43    @Override
44    public boolean getSimilarity(IGUIElementSpec other) {
45        if (this == other)
46        {
47            return true;
48        }
49       
50        if (!(other instanceof JFCGUIElementSpec))
51        {
52            return false;
53        }
54       
55        JFCGUIElementSpec otherSpec = (JFCGUIElementSpec) other;
56       
57        boolean retVal = false;
58       
59        boolean titleEqual = CollectionUtils.containsAny(name, otherSpec.name);
60        boolean hashEqual = CollectionUtils.containsAny(elementHash, otherSpec.elementHash);
61       
62        if( type.equals("Class") ) {
63            retVal = type.equals(otherSpec.type) && (titleEqual || hashEqual);
64        } else {
65            retVal = type.equals(otherSpec.type) && index==otherSpec.index && (titleEqual || hashEqual);
66        }
67       
68        return retVal;
69    }
70
71    /* (non-Javadoc)
72     * @see de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#equals(IGUIElementSpec)
73     */
74    @Override
75    public boolean equals(IGUIElementSpec other) {
76        if (this == other)
77        {
78            return true;
79        }
80       
81        if (!(other instanceof JFCGUIElementSpec))
82        {
83            return false;
84        }
85       
86        JFCGUIElementSpec otherSpec = (JFCGUIElementSpec) other;
87       
88        return
89            ((name == otherSpec.name) || ((name != null) && (name.equals(otherSpec.name)))) &&
90            ((type == otherSpec.type) || ((type != null) && (type.equals(otherSpec.type)))) &&
91            ((icon == otherSpec.icon) || ((icon != null) && (icon.equals(otherSpec.icon)))) &&
92            (index == otherSpec.index) && (elementHash == otherSpec.elementHash);
93    }
94
95    /**
96     * @return the name
97     */
98    public String getName() {
99        // TODO for now always returns first matched name
100        if( name.isEmpty() ) {
101            return null;
102        }
103        return name.get(0);
104    }
105
106    /**
107     * @return the title
108     */
109    public String getType() {
110        return type;
111    }
112
113    /**
114     * @return the icon
115     */
116    public String getIcon() {
117        return icon;
118    }
119
120    /**
121     * @return the index
122     */
123    public int getIndex() {
124        return index;
125    }
126
127    /**
128     * @return the elementHash
129     */
130    public String getElementHash() {
131        // TODO for now always returns the first hash value
132        if( elementHash.isEmpty() ) {
133            return null;
134        }
135        return elementHash.get(0);
136    }
137
138    /**
139     * @param name the name to set
140     */
141    public void setName(String name) {
142        if( !this.name.contains(name) && name!=null ) {
143            this.name.add(name);
144        }
145    }
146
147    /**
148     * @param title the title to set
149     */
150    public void setType(String type) {
151        this.type = type;
152    }
153
154    /**
155     * @param icon the icon to set
156     */
157    public void setIcon(String icon) {
158        this.icon = icon;
159    }
160
161    /**
162     * @param index the index to set
163     */
164    public void setIndex(int index) {
165        this.index = index;
166    }
167
168    /**
169     * @param elementHash the elementHash to set
170     */
171    public void setElementHash(String elementHash) {
172        if( !this.elementHash.contains(elementHash) ) {
173            this.elementHash.add(elementHash);
174        }
175    }
176
177}
Note: See TracBrowser for help on using the repository browser.