commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r515834 - in /jakarta/commons/proper/scxml/trunk/src: main/java/org/apache/commons/scxml/io/ main/java/org/apache/commons/scxml/model/ test/java/org/apache/commons/scxml/model/
Date Wed, 07 Mar 2007 23:08:52 GMT
Author: rahul
Date: Wed Mar  7 15:08:50 2007
New Revision: 515834

URL: http://svn.apache.org/viewvc?view=rev&rev=515834
Log:
Changes to the object model:
 - Store transitions as a list rather than a map. The slightly more intense data structure
used to hold transitions previously doesn't really pay off much, and more importantly, gets
in the way of retaining document order.
 - Deprecate oacs.model.State#getTransitions()
 - Remove calls to deprecated API from source and tests
 - Retain document order where necessary
 - Minor cleanup in oacs.model.Path

Modified:
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Parallel.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Path.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java
    jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StateTest.java

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java?view=diff&rev=515834&r1=515833&r2=515834
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java
Wed Mar  7 15:08:50 2007
@@ -150,16 +150,12 @@
                 }
             }
         }
-        Map t = s.getTransitions();
-        Iterator i = t.keySet().iterator();
-        while (i.hasNext()) {
-            Iterator j = ((List) t.get(i.next())).iterator();
-            while (j.hasNext()) {
-                Transition trn = (Transition) j.next();
-                //could add next two lines as a Digester rule for Transition
-                trn.setParent(s);
-                updateTransition(trn, targets);
-            }
+        List t = s.getTransitionsList();
+        for (int i = 0; i < t.size(); i++) {
+            Transition trn = (Transition) t.get(i);
+            //could add next two lines as a Digester rule for Transition
+            trn.setParent(s);
+            updateTransition(trn, targets);
         }
         Parallel p = s.getParallel();
         Invoke inv = s.getInvoke();

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java?view=diff&rev=515834&r1=515833&r2=515834
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java
Wed Mar  7 15:08:50 2007
@@ -138,14 +138,9 @@
             serializeDatamodel(b, dm, indent + INDENT);
         }
         serializeOnEntry(b, s, indent + INDENT);
-        Map t = s.getTransitions();
-        Iterator i = t.keySet().iterator();
-        while (i.hasNext()) {
-            List et = (List) t.get(i.next());
-            for (int len = 0; len < et.size(); len++) {
-                serializeTransition(b, (Transition) et.get(len), indent
-                    + INDENT);
-            }
+        List t = s.getTransitionsList();
+        for (int i = 0; i < t.size(); i++) {
+            serializeTransition(b, (Transition) t.get(i), indent + INDENT);
         }
         Parallel p = s.getParallel();
         Invoke inv = s.getInvoke();

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Parallel.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Parallel.java?view=diff&rev=515834&r1=515833&r2=515834
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Parallel.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Parallel.java
Wed Mar  7 15:08:50 2007
@@ -16,7 +16,7 @@
  */
 package org.apache.commons.scxml.model;
 
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Set;
 
 /**
@@ -44,7 +44,7 @@
      * Constructor.
      */
     public Parallel() {
-        this.states = new HashSet();
+        this.states = new LinkedHashSet();
     }
 
     /**

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Path.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Path.java?view=diff&rev=515834&r1=515833&r2=515834
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Path.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Path.java
Wed Mar  7 15:08:50 2007
@@ -128,7 +128,7 @@
      * @see State#isRegion()
      */
     public final List getRegionsExited() {
-        LinkedList ll = new LinkedList();
+        List ll = new LinkedList();
         for (Iterator i = upSeg.iterator(); i.hasNext();) {
             Object o = i.next();
             if (o instanceof State) {
@@ -149,7 +149,7 @@
      * @see State#isRegion()
      */
     public final List getRegionsEntered() {
-        LinkedList ll = new LinkedList();
+        List ll = new LinkedList();
         for (Iterator i = downSeg.iterator(); i.hasNext();) {
             Object o = i.next();
             if (o instanceof State) {

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java?view=diff&rev=515834&r1=515833&r2=515834
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java
Wed Mar  7 15:08:50 2007
@@ -18,6 +18,7 @@
 
 import java.io.Serializable;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 import org.apache.commons.scxml.SCXMLHelper;
@@ -83,7 +84,7 @@
      * Constructor.
      */
     public SCXML() {
-        this.states = new HashMap();
+        this.states = new LinkedHashMap();
         this.targets = new HashMap();
     }
 

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java?view=diff&rev=515834&r1=515833&r2=515834
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java
Wed Mar  7 15:08:50 2007
@@ -18,7 +18,7 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -70,9 +70,9 @@
     private Initial initial;
 
     /**
-     * A map of outgoing Transitions from this state.
+     * A list of outgoing Transitions from this state, by document order.
      */
-    private Map transitions;
+    private List transitions;
 
     /**
      * List of history states owned by a given state (applies to non-leaf
@@ -91,8 +91,8 @@
      * Constructor.
      */
     public State() {
-        this.children = new HashMap();
-        this.transitions = new HashMap();
+        this.children = new LinkedHashMap();
+        this.transitions = new ArrayList();
         this.history = new ArrayList();
     }
 
@@ -176,9 +176,22 @@
      * Get the map of all outgoing transitions from this state.
      *
      * @return Map Returns the transitions Map.
+     * @deprecated Use getTransitionsList() instead
      */
     public final Map getTransitions() {
-        return transitions;
+        Map transitionsMap = new HashMap();
+        for (int i = 0; i < transitions.size(); i++) {
+            Transition transition = (Transition) transitions.get(i);
+            String event = transition.getEvent();
+            if (!transitionsMap.containsKey(event)) {
+                List eventTransitions = new ArrayList();
+                eventTransitions.add(transition);
+                transitionsMap.put(event, eventTransitions);
+            } else {
+                ((List) transitionsMap.get(event)).add(transition);
+            }
+        }
+        return transitionsMap;
     }
 
     /**
@@ -189,11 +202,18 @@
      * @return List Returns the candidate transitions for given event
      */
     public final List getTransitionsList(final String event) {
-        Object candidateTransitions = transitions.get(event);
-        if (candidateTransitions == null) {
-            return null;
+        List matchingTransitions = null; // since we returned null upto v0.6
+        for (int i = 0; i < transitions.size(); i++) {
+            Transition t = (Transition) transitions.get(i);
+            if ((event == null && t.getEvent() == null)
+                    || (event != null && event.equals(t.getEvent()))) {
+                if (matchingTransitions == null) {
+                    matchingTransitions = new ArrayList();
+                }
+                matchingTransitions.add(t);
+            }
         }
-        return (List) candidateTransitions;
+        return matchingTransitions;
     }
 
     /**
@@ -204,14 +224,7 @@
      *            The transitions to set.
      */
     public final void addTransition(final Transition transition) {
-        String event = transition.getEvent();
-        if (!transitions.containsKey(event)) {
-            List eventTransitions = new ArrayList();
-            eventTransitions.add(transition);
-            transitions.put(event, eventTransitions);
-        } else {
-            ((List) transitions.get(event)).add(transition);
-        }
+        transitions.add(transition);
     }
 
     /**
@@ -237,17 +250,10 @@
     /**
      * Get the outgoing transitions for this state as a java.util.List.
      *
-     * @return List Returns the transitions (as a list). TODO - Check in next
-     *         iteration whether both methods need to be retained.
+     * @return List Returns the transitions list.
      */
     public final List getTransitionsList() {
-        // Each call creates a new List, this will change once TO-DO is handled
-        List transitionsList = new ArrayList();
-        for (Iterator iter = transitions.keySet().iterator();
-                iter.hasNext();) {
-            transitionsList.addAll((List) transitions.get(iter.next()));
-        }
-        return transitionsList;
+        return transitions;
     }
 
     /**

Modified: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StateTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StateTest.java?view=diff&rev=515834&r1=515833&r2=515834
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StateTest.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StateTest.java
Wed Mar  7 15:08:50 2007
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.scxml.model;
 
-import java.util.ArrayList;
 import java.util.List;
 
 import junit.framework.Test;
@@ -49,11 +48,10 @@
     }
     
     public void testGetTransitionsList() {
-        List values = new ArrayList();
         
-        state.getTransitions().put("event", values);
+        state.getTransitionsList().add(new Transition());
         
-        assertNotNull(state.getTransitionsList("event"));
+        assertNotNull(state.getTransitionsList(null));
     }
     
     public void testAddTransitionDoesNotContainKey() {
@@ -62,7 +60,7 @@
         
         state.addTransition(transition);
         
-        List events = (List)state.getTransitions().get("event");
+        List events = (List)state.getTransitionsList("event");
         
         assertEquals(1, events.size());
         assertEquals("event", ((Transition)events.get(0)).getEvent());
@@ -78,7 +76,7 @@
         state.addTransition(transition1);
         state.addTransition(transition2);
         
-        List events = (List)state.getTransitions().get("event");
+        List events = (List)state.getTransitionsList("event");
         
         assertEquals(2, events.size());
     }



---------------------------------------------------------------------
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