Changeset 796
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-plugin-jfc-test/src/test/java/de/ugoe/cs/quest/plugin/jfc/JFCReplayIDCalculatorTest.java
r675 r796 2 2 3 3 import java.io.File; 4 import java.util.ArrayList; 4 5 import java.util.Collection; 5 6 import java.util.HashSet; … … 13 14 14 15 import de.ugoe.cs.quest.eventcore.Event; 16 import de.ugoe.cs.quest.eventcore.IEventTarget; 15 17 import de.ugoe.cs.quest.plugin.jfc.eventcore.JFCEventId; 18 import de.ugoe.cs.quest.plugin.jfc.guimodel.JFCGUIElement; 19 import de.ugoe.cs.quest.plugin.jfc.guimodel.JFCGUIElementSpec; 16 20 17 21 /** … … 46 50 */ 47 51 @Test 48 public void testCalculateReplayID _1()52 public void testCalculateReplayIDwithEvent() 49 53 throws Exception { 50 54 Collection<JFCEventId> ignoredEvents = new HashSet<JFCEventId>(); … … 57 61 58 62 String result = new JFCReplayIDCalculator().calculateReplayID(event); 63 assertEquals("e3561778462", result); 64 } 65 66 /** 67 * Run the String calculateReplayID(List<JFCGUIElementSpec>) method test. 68 * 69 * @throws Exception 70 */ 71 @Test 72 public void testCalculateReplayIDwithGuiElementPath() 73 throws Exception { 74 Collection<JFCEventId> ignoredEvents = new HashSet<JFCEventId>(); 75 ignoredEvents.add(JFCEventId.FOCUS_GAINED); 76 JFCLogParser parser = new JFCLogParser(ignoredEvents); 77 parser.parseFile(new File(ClassLoader.getSystemResource("freemind_trace.xml").getFile())); 78 79 Collection<List<Event>> sequences = parser.getSequences(); 80 Event event = sequences.iterator().next().get(0); 81 82 List<JFCGUIElementSpec> guiElementPath = new ArrayList<JFCGUIElementSpec>(); 83 84 IEventTarget target = event.getTarget(); 85 JFCGUIElement jfcTarget = (JFCGUIElement) target; 86 87 // extract element path 88 JFCGUIElement currentTarget = jfcTarget; 89 while (currentTarget != null){ 90 JFCGUIElementSpec currentSpec = (JFCGUIElementSpec) currentTarget.getSpecification(); 91 guiElementPath.add(0, currentSpec); 92 currentTarget = (JFCGUIElement) currentTarget.getParent(); 93 } 94 95 String result = new JFCReplayIDCalculator().calculateReplayID(guiElementPath); 59 96 assertEquals("e3561778462", result); 60 97 } -
trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/JFCReplayIDCalculator.java
r785 r796 1 1 package de.ugoe.cs.quest.plugin.jfc; 2 2 3 import java.util.ArrayList; 3 4 import java.util.Arrays; 4 5 import java.util.LinkedHashMap; 5 6 import java.util.List; 7 import java.util.ListIterator; 6 8 import java.util.Map; 7 import java.util.Stack;8 9 import java.util.regex.Matcher; 9 10 import java.util.regex.Pattern; … … 50 51 "javax.swing.JScrollPane$ScrollBar", 51 52 "javax.swing.plaf.metal.MetalScrollButton"); 52 53 54 /** 55 * Calculates the replayID needed for compatibility with Guitar suite of a JFCEvent 53 54 /** 55 * Calculates the replayID of a JFCEvent needed for compatibility with guitar suite 56 * @param List of {@link JFCGUIElementSpec}s that represent the component path of a event target 57 * for which the replayID should be calculated. 58 * @return replayID 59 */ 60 61 public String calculateReplayID(List<JFCGUIElementSpec> guiElementPath){ 62 String replayID = ""; 63 long hashCode = 1; 64 65 ListIterator<JFCGUIElementSpec> iterator = guiElementPath.listIterator(); 66 67 JFCGUIElementSpec currentSpec = iterator.next(); 68 String title = currentSpec.getName(); 69 String fuzzyTitle = getFuzzyTitle(title); 70 long windowHashCode = fuzzyTitle.hashCode(); 71 windowHashCode = (windowHashCode * 2) & 0xffffffffL; 72 73 long propagatedHashCode = windowHashCode; 74 75 // construct looks complicated but avoids going back and force through path 76 if (iterator.hasNext()) 77 currentSpec = iterator.next(); 78 else 79 currentSpec = null; 80 81 // walk through component path and calculate hashcode 82 while(currentSpec != null){ 83 long localHashCode = getLocalHashCode(currentSpec); 84 hashCode = propagatedHashCode * prime + localHashCode; 85 hashCode = (hashCode * 2) & 0xffffffffL; 86 87 if (iterator.hasNext()){ 88 currentSpec = iterator.next(); 89 Integer index = currentSpec.getIndex(); 90 propagatedHashCode = prime * propagatedHashCode 91 + index.hashCode(); 92 } 93 else 94 currentSpec = null; 95 96 } 97 98 replayID = "e" + hashCode; 99 100 return replayID; 101 } 102 103 104 /** 105 * Calculates the replayID of a JFCEvent needed for compatibility with guitar suite 56 106 * @param event for which the ID should be calculated 57 107 * @return replayID 58 108 */ 59 109 public String calculateReplayID(Event event){ 60 String replayID = ""; 61 long hashCode = 1; 62 Stack<JFCGUIElement> path = new Stack<JFCGUIElement>(); 110 List<JFCGUIElementSpec> guiElementPath = new ArrayList<JFCGUIElementSpec>(); 63 111 64 112 IEventTarget target = event.getTarget(); 65 113 JFCGUIElement jfcTarget = (JFCGUIElement) target; 66 114 67 // extract target path115 // extract element path 68 116 JFCGUIElement currentTarget = jfcTarget; 69 117 while (currentTarget != null){ 70 path.push(currentTarget); 118 JFCGUIElementSpec currentSpec = (JFCGUIElementSpec) currentTarget.getSpecification(); 119 guiElementPath.add(0, currentSpec); 71 120 currentTarget = (JFCGUIElement) currentTarget.getParent(); 72 121 } 73 122 74 // calculate window hashcode 75 currentTarget = path.pop(); 76 77 JFCGUIElementSpec currentSpec = (JFCGUIElementSpec) currentTarget.getSpecification(); 78 String title = currentSpec.getName(); 79 String fuzzyTitle = getFuzzyTitle(title); 80 long windowHashCode = fuzzyTitle.hashCode(); 81 windowHashCode = (windowHashCode * 2) & 0xffffffffL; 82 83 long propagatedHashCode = windowHashCode; 84 85 // walk through component path and calculate hashcode 86 87 while(!path.isEmpty()){ 88 currentTarget = path.pop(); 89 currentSpec = (JFCGUIElementSpec) currentTarget.getSpecification(); 90 long localHashCode = getLocalHashCode(currentSpec); 91 hashCode = propagatedHashCode * prime + localHashCode; 92 hashCode = (hashCode * 2) & 0xffffffffL; 93 94 if (!path.isEmpty()){ 95 Integer index = ((JFCGUIElementSpec) path.lastElement().getSpecification()).getIndex(); 96 propagatedHashCode = prime * propagatedHashCode 97 + index.hashCode(); 98 } 99 } 100 101 replayID = "e" + hashCode; 102 103 return replayID; 123 // calculation is delegated to other calculateReplayID method 124 return this.calculateReplayID(guiElementPath); 104 125 } 105 126
Note: See TracChangeset
for help on using the changeset viewer.