[573] | 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 |
---|
| 6 | package de.ugoe.cs.quest.plugin.jfc.guimodel; |
---|
| 7 | |
---|
[589] | 8 | import java.util.LinkedList; |
---|
| 9 | import java.util.List; |
---|
| 10 | |
---|
| 11 | import org.apache.commons.collections15.CollectionUtils; |
---|
| 12 | |
---|
[573] | 13 | import 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 | */ |
---|
| 23 | public class JFCGUIElementSpec implements IGUIElementSpec { |
---|
| 24 | |
---|
| 25 | /** */ |
---|
[589] | 26 | private List<String> name = new LinkedList<String>(); |
---|
[573] | 27 | |
---|
| 28 | /** */ |
---|
[588] | 29 | private String type = null; |
---|
[573] | 30 | |
---|
| 31 | /** */ |
---|
[588] | 32 | private String icon = null; |
---|
[573] | 33 | |
---|
| 34 | /** */ |
---|
[588] | 35 | private int index = -1; |
---|
[573] | 36 | |
---|
| 37 | /** */ |
---|
[589] | 38 | private List<String> elementHash = new LinkedList<String>(); |
---|
[573] | 39 | |
---|
| 40 | /* (non-Javadoc) |
---|
| 41 | * @see de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#getSecificationSimilarity(IGUIElementSpec) |
---|
| 42 | */ |
---|
| 43 | @Override |
---|
[589] | 44 | public boolean getSimilarity(IGUIElementSpec other) { |
---|
[573] | 45 | if (this == other) |
---|
| 46 | { |
---|
[589] | 47 | return true; |
---|
[573] | 48 | } |
---|
| 49 | |
---|
| 50 | if (!(other instanceof JFCGUIElementSpec)) |
---|
| 51 | { |
---|
[589] | 52 | return false; |
---|
[573] | 53 | } |
---|
| 54 | |
---|
| 55 | JFCGUIElementSpec otherSpec = (JFCGUIElementSpec) other; |
---|
[589] | 56 | |
---|
| 57 | boolean retVal = false; |
---|
| 58 | |
---|
| 59 | boolean titleEqual = CollectionUtils.containsAny(name, otherSpec.name); |
---|
| 60 | boolean hashEqual = CollectionUtils.containsAny(elementHash, otherSpec.elementHash); |
---|
| 61 | |
---|
[600] | 62 | if (type.equals("Class") ) { |
---|
[589] | 63 | retVal = type.equals(otherSpec.type) && (titleEqual || hashEqual); |
---|
[573] | 64 | } |
---|
[600] | 65 | else { |
---|
| 66 | retVal = type.equals(otherSpec.type) && index==otherSpec.index && |
---|
| 67 | (titleEqual || hashEqual); |
---|
| 68 | } |
---|
[573] | 69 | |
---|
[589] | 70 | return retVal; |
---|
[573] | 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 | |
---|
[600] | 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 | |
---|
[573] | 105 | /** |
---|
| 106 | * @return the name |
---|
| 107 | */ |
---|
| 108 | public String getName() { |
---|
[589] | 109 | // TODO for now always returns first matched name |
---|
| 110 | if( name.isEmpty() ) { |
---|
| 111 | return null; |
---|
| 112 | } |
---|
| 113 | return name.get(0); |
---|
[573] | 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 | */ |
---|
[588] | 140 | public String getElementHash() { |
---|
[589] | 141 | // TODO for now always returns the first hash value |
---|
| 142 | if( elementHash.isEmpty() ) { |
---|
| 143 | return null; |
---|
| 144 | } |
---|
| 145 | return elementHash.get(0); |
---|
[573] | 146 | } |
---|
| 147 | |
---|
| 148 | /** |
---|
| 149 | * @param name the name to set |
---|
| 150 | */ |
---|
| 151 | public void setName(String name) { |
---|
[589] | 152 | if( !this.name.contains(name) && name!=null ) { |
---|
| 153 | this.name.add(name); |
---|
| 154 | } |
---|
[573] | 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 | */ |
---|
[588] | 181 | public void setElementHash(String elementHash) { |
---|
[589] | 182 | if( !this.elementHash.contains(elementHash) ) { |
---|
| 183 | this.elementHash.add(elementHash); |
---|
| 184 | } |
---|
[573] | 185 | } |
---|
[607] | 186 | |
---|
| 187 | public String toString() { |
---|
| 188 | return "" + name.toString() + "," + elementHash.toString() + "," + type + "," + "icon"; |
---|
| 189 | } |
---|
[573] | 190 | |
---|
| 191 | } |
---|