commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r517386 - in /jakarta/commons/proper/scxml/trunk/src: main/java/org/apache/commons/scxml/semantics/TransitionTargetComparator.java test/java/org/apache/commons/scxml/semantics/TransitionTargetComparatorTest.java
Date Mon, 12 Mar 2007 20:40:39 GMT
Author: rahul
Date: Mon Mar 12 13:40:38 2007
New Revision: 517386

URL: http://svn.apache.org/viewvc?view=rev&rev=517386
Log:
Use document order as a priority for deciding order in which regions of a parallel are entered.
While this is not required by the specification, it is useful to have repeatable behavior
for an implementation, and goes hand-in-hand with the other changes made recently. Users should
not rely on this order, as it will make their code non-portable.

Modified:
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/TransitionTargetComparator.java
    jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/TransitionTargetComparatorTest.java

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/TransitionTargetComparator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/TransitionTargetComparator.java?view=diff&rev=517386&r1=517385&r2=517386
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/TransitionTargetComparator.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/TransitionTargetComparator.java
Mon Mar 12 13:40:38 2007
@@ -18,8 +18,11 @@
 
 import java.io.Serializable;
 import java.util.Comparator;
+import java.util.Iterator;
 
 import org.apache.commons.scxml.SCXMLHelper;
+import org.apache.commons.scxml.model.Parallel;
+import org.apache.commons.scxml.model.State;
 import org.apache.commons.scxml.model.TransitionTarget;
 
 
@@ -68,6 +71,29 @@
             //the tt1 and tt2 are parallel, now we have to count chain sizes
             int tc1 = countChainLength(tt1);
             int tc2 = countChainLength(tt2);
+            if (tc2 == tc1) {
+                // use document order as priority
+                // - not a requirement
+                // - though useful for an impl to have repeatable behavior
+                // - downside is users may rely on this behavior
+                Parallel lca = (Parallel) SCXMLHelper.getLCA(tt1, tt2);
+                TransitionTarget parent1 = tt1;
+                while (parent1.getParent() != lca) {
+                    parent1 = parent1.getParent();
+                }
+                TransitionTarget parent2 = tt2;
+                while (parent2.getParent() != lca) {
+                    parent2 = parent2.getParent();
+                }
+                for (Iterator iter = lca.getStates().iterator(); iter.hasNext();) {
+                    State s = (State) iter.next();
+                    if (s == parent1) {
+                        return 1;
+                    } else if (s == parent2) {
+                        return -1;
+                    }
+                }
+            }
             //longer the chain, deeper the node is
             return tc2 - tc1;
         }

Modified: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/TransitionTargetComparatorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/TransitionTargetComparatorTest.java?view=diff&rev=517386&r1=517385&r2=517386
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/TransitionTargetComparatorTest.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/TransitionTargetComparatorTest.java
Mon Mar 12 13:40:38 2007
@@ -16,13 +16,14 @@
  */
 package org.apache.commons.scxml.semantics;
 
-import org.apache.commons.scxml.model.State;
-import org.apache.commons.scxml.model.TransitionTarget;
-
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.apache.commons.scxml.model.Parallel;
+import org.apache.commons.scxml.model.State;
+import org.apache.commons.scxml.model.TransitionTarget;
+
 public class TransitionTargetComparatorTest extends TestCase {
 
     public TransitionTargetComparatorTest(String testName) {
@@ -100,17 +101,16 @@
         assertEquals(1, comparator.compare(target2, target1)); // reversed
     }
     
-    public void testComparatorSameParents() {
-        TransitionTarget target1 = new State();
-        TransitionTarget parent1 = new State();
-
-        target1.setParent(parent1);
+    public void testComparatorSameParent() {
+        State target1 = new State();
+        Parallel parent = new Parallel();
+        target1.setParent(parent);
+        parent.addState(target1);
+        
+        State target2 = new State();
+        target2.setParent(parent);
+        parent.addState(target2);
         
-        TransitionTarget target2 = new State();
-        TransitionTarget parent2 = new State();
-        
-        target2.setParent(parent2);
-        
-        assertEquals(0, comparator.compare(target1, target2));
+        assertEquals(1, comparator.compare(target1, target2));
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message