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

Last change on this file since 600 was 600, checked in by pharms, 12 years ago
  • added hashCode, but will perhaps be reverted later
File size: 4.4 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        }
65        else {
66            retVal = type.equals(otherSpec.type) && index==otherSpec.index &&
67                (titleEqual || hashEqual);
68        }
69       
70        return retVal;
71    }
72
73    /* (non-Javadoc)
74     * @see de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#equals(IGUIElementSpec)
75     */
76    @Override
77    public boolean equals(IGUIElementSpec other) {
78        if (this == other)
79        {
80            return true;
81        }
82       
83        if (!(other instanceof JFCGUIElementSpec))
84        {
85            return false;
86        }
87       
88        JFCGUIElementSpec otherSpec = (JFCGUIElementSpec) other;
89       
90        return
91            ((name == otherSpec.name) || ((name != null) && (name.equals(otherSpec.name)))) &&
92            ((type == otherSpec.type) || ((type != null) && (type.equals(otherSpec.type)))) &&
93            ((icon == otherSpec.icon) || ((icon != null) && (icon.equals(otherSpec.icon)))) &&
94            (index == otherSpec.index) && (elementHash == otherSpec.elementHash);
95    }
96
97    /* (non-Javadoc)
98     * @see java.lang.Object#hashCode()
99     */
100    @Override
101    public int hashCode() {
102        return (name + type + icon + index + elementHash).hashCode();
103    }
104
105    /**
106     * @return the name
107     */
108    public String getName() {
109        // TODO for now always returns first matched name
110        if( name.isEmpty() ) {
111            return null;
112        }
113        return name.get(0);
114    }
115
116    /**
117     * @return the title
118     */
119    public String getType() {
120        return type;
121    }
122
123    /**
124     * @return the icon
125     */
126    public String getIcon() {
127        return icon;
128    }
129
130    /**
131     * @return the index
132     */
133    public int getIndex() {
134        return index;
135    }
136
137    /**
138     * @return the elementHash
139     */
140    public String getElementHash() {
141        // TODO for now always returns the first hash value
142        if( elementHash.isEmpty() ) {
143            return null;
144        }
145        return elementHash.get(0);
146    }
147
148    /**
149     * @param name the name to set
150     */
151    public void setName(String name) {
152        if( !this.name.contains(name) && name!=null ) {
153            this.name.add(name);
154        }
155    }
156
157    /**
158     * @param title the title to set
159     */
160    public void setType(String type) {
161        this.type = type;
162    }
163
164    /**
165     * @param icon the icon to set
166     */
167    public void setIcon(String icon) {
168        this.icon = icon;
169    }
170
171    /**
172     * @param index the index to set
173     */
174    public void setIndex(int index) {
175        this.index = index;
176    }
177
178    /**
179     * @param elementHash the elementHash to set
180     */
181    public void setElementHash(String elementHash) {
182        if( !this.elementHash.contains(elementHash) ) {
183            this.elementHash.add(elementHash);
184        }
185    }
186
187}
Note: See TracBrowser for help on using the repository browser.