[573] | 1 | package de.ugoe.cs.quest.plugin.jfc.guimodel; |
---|
| 2 | |
---|
[589] | 3 | import java.util.LinkedList; |
---|
| 4 | import java.util.List; |
---|
| 5 | |
---|
| 6 | import org.apache.commons.collections15.CollectionUtils; |
---|
| 7 | |
---|
[573] | 8 | import de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec; |
---|
| 9 | |
---|
| 10 | /** |
---|
| 11 | * <p> |
---|
| 12 | * TODO comment |
---|
| 13 | * </p> |
---|
| 14 | * |
---|
| 15 | * @version $Revision: $ $Date: 17.08.2012$ |
---|
| 16 | * @author 2012, last modified by $Author: pharms$ |
---|
| 17 | */ |
---|
| 18 | public class JFCGUIElementSpec implements IGUIElementSpec { |
---|
| 19 | |
---|
| 20 | /** */ |
---|
[589] | 21 | private List<String> name = new LinkedList<String>(); |
---|
[573] | 22 | |
---|
| 23 | /** */ |
---|
[588] | 24 | private String type = null; |
---|
[573] | 25 | |
---|
| 26 | /** */ |
---|
[588] | 27 | private String icon = null; |
---|
[573] | 28 | |
---|
| 29 | /** */ |
---|
[588] | 30 | private int index = -1; |
---|
[573] | 31 | |
---|
| 32 | /** */ |
---|
[589] | 33 | private List<String> elementHash = new LinkedList<String>(); |
---|
[573] | 34 | |
---|
| 35 | /* (non-Javadoc) |
---|
| 36 | * @see de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#getSecificationSimilarity(IGUIElementSpec) |
---|
| 37 | */ |
---|
| 38 | @Override |
---|
[589] | 39 | public boolean getSimilarity(IGUIElementSpec other) { |
---|
[573] | 40 | if (this == other) |
---|
| 41 | { |
---|
[589] | 42 | return true; |
---|
[573] | 43 | } |
---|
| 44 | |
---|
| 45 | if (!(other instanceof JFCGUIElementSpec)) |
---|
| 46 | { |
---|
[589] | 47 | return false; |
---|
[573] | 48 | } |
---|
| 49 | |
---|
| 50 | JFCGUIElementSpec otherSpec = (JFCGUIElementSpec) other; |
---|
[589] | 51 | |
---|
| 52 | boolean retVal = false; |
---|
| 53 | |
---|
| 54 | boolean titleEqual = CollectionUtils.containsAny(name, otherSpec.name); |
---|
| 55 | boolean hashEqual = CollectionUtils.containsAny(elementHash, otherSpec.elementHash); |
---|
| 56 | |
---|
[600] | 57 | if (type.equals("Class") ) { |
---|
[589] | 58 | retVal = type.equals(otherSpec.type) && (titleEqual || hashEqual); |
---|
[573] | 59 | } |
---|
[600] | 60 | else { |
---|
| 61 | retVal = type.equals(otherSpec.type) && index==otherSpec.index && |
---|
| 62 | (titleEqual || hashEqual); |
---|
| 63 | } |
---|
[573] | 64 | |
---|
[589] | 65 | return retVal; |
---|
[573] | 66 | } |
---|
| 67 | |
---|
| 68 | /* (non-Javadoc) |
---|
| 69 | * @see de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#equals(IGUIElementSpec) |
---|
| 70 | */ |
---|
| 71 | @Override |
---|
| 72 | public boolean equals(IGUIElementSpec other) { |
---|
| 73 | if (this == other) |
---|
| 74 | { |
---|
| 75 | return true; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | if (!(other instanceof JFCGUIElementSpec)) |
---|
| 79 | { |
---|
| 80 | return false; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | JFCGUIElementSpec otherSpec = (JFCGUIElementSpec) other; |
---|
| 84 | |
---|
| 85 | return |
---|
| 86 | ((name == otherSpec.name) || ((name != null) && (name.equals(otherSpec.name)))) && |
---|
| 87 | ((type == otherSpec.type) || ((type != null) && (type.equals(otherSpec.type)))) && |
---|
| 88 | ((icon == otherSpec.icon) || ((icon != null) && (icon.equals(otherSpec.icon)))) && |
---|
| 89 | (index == otherSpec.index) && (elementHash == otherSpec.elementHash); |
---|
| 90 | } |
---|
| 91 | |
---|
[600] | 92 | /* (non-Javadoc) |
---|
| 93 | * @see java.lang.Object#hashCode() |
---|
| 94 | */ |
---|
| 95 | @Override |
---|
| 96 | public int hashCode() { |
---|
| 97 | return (name + type + icon + index + elementHash).hashCode(); |
---|
| 98 | } |
---|
| 99 | |
---|
[573] | 100 | /** |
---|
| 101 | * @return the name |
---|
| 102 | */ |
---|
| 103 | public String getName() { |
---|
[589] | 104 | // TODO for now always returns first matched name |
---|
| 105 | if( name.isEmpty() ) { |
---|
| 106 | return null; |
---|
| 107 | } |
---|
| 108 | return name.get(0); |
---|
[573] | 109 | } |
---|
| 110 | |
---|
| 111 | /** |
---|
| 112 | * @return the title |
---|
| 113 | */ |
---|
| 114 | public String getType() { |
---|
| 115 | return type; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | /** |
---|
| 119 | * @return the icon |
---|
| 120 | */ |
---|
| 121 | public String getIcon() { |
---|
| 122 | return icon; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | /** |
---|
| 126 | * @return the index |
---|
| 127 | */ |
---|
| 128 | public int getIndex() { |
---|
| 129 | return index; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | /** |
---|
| 133 | * @return the elementHash |
---|
| 134 | */ |
---|
[588] | 135 | public String getElementHash() { |
---|
[589] | 136 | // TODO for now always returns the first hash value |
---|
| 137 | if( elementHash.isEmpty() ) { |
---|
| 138 | return null; |
---|
| 139 | } |
---|
| 140 | return elementHash.get(0); |
---|
[573] | 141 | } |
---|
| 142 | |
---|
| 143 | /** |
---|
| 144 | * @param name the name to set |
---|
| 145 | */ |
---|
| 146 | public void setName(String name) { |
---|
[589] | 147 | if( !this.name.contains(name) && name!=null ) { |
---|
| 148 | this.name.add(name); |
---|
| 149 | } |
---|
[573] | 150 | } |
---|
| 151 | |
---|
| 152 | /** |
---|
| 153 | * @param title the title to set |
---|
| 154 | */ |
---|
| 155 | public void setType(String type) { |
---|
| 156 | this.type = type; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | /** |
---|
| 160 | * @param icon the icon to set |
---|
| 161 | */ |
---|
| 162 | public void setIcon(String icon) { |
---|
| 163 | this.icon = icon; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | /** |
---|
| 167 | * @param index the index to set |
---|
| 168 | */ |
---|
| 169 | public void setIndex(int index) { |
---|
| 170 | this.index = index; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | /** |
---|
| 174 | * @param elementHash the elementHash to set |
---|
| 175 | */ |
---|
[588] | 176 | public void setElementHash(String elementHash) { |
---|
[589] | 177 | if( !this.elementHash.contains(elementHash) ) { |
---|
| 178 | this.elementHash.add(elementHash); |
---|
| 179 | } |
---|
[573] | 180 | } |
---|
[607] | 181 | |
---|
| 182 | public String toString() { |
---|
| 183 | return "" + name.toString() + "," + elementHash.toString() + "," + type + "," + "icon"; |
---|
| 184 | } |
---|
[573] | 185 | |
---|
| 186 | } |
---|