Author: luc
Date: Sun Sep 25 12:39:09 2011
New Revision: 1175379

URL: http://svn.apache.org/viewvc?rev=1175379&view=rev
Log:
Changed return type for eventOccurred from int to an enumerate in ODE.

Modified:
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventHandler.java
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/TestProblem4.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/OverlappingEventsTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/StepProblem.java

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventHandler.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventHandler.java?rev=1175379&r1=1175378&r2=1175379&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventHandler.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventHandler.java
 Sun Sep 25 12:39:09 2011
@@ -49,38 +49,43 @@ package org.apache.commons.math.ode.even
 
 public interface EventHandler  {
 
-  /** Stop indicator.
-   * <p>This value should be used as the return value of the {@link
-   * #eventOccurred eventOccurred} method when the integration should be
-   * stopped after the event ending the current step.</p>
-   */
-  int STOP = 0;
+    /** Enumerate for actions to be performed when an event occurs. */
+    public enum Action {
 
-  /** Reset state indicator.
-   * <p>This value should be used as the return value of the {@link
-   * #eventOccurred eventOccurred} method when the integration should
-   * go on after the event ending the current step, with a new state
-   * vector (which will be retrieved thanks to the {@link #resetState
-   * resetState} method).</p>
-   */
-  int RESET_STATE = 1;
+        /** Stop indicator.
+         * <p>This value should be used as the return value of the {@link
+         * #eventOccurred eventOccurred} method when the integration should be
+         * stopped after the event ending the current step.</p>
+         */
+        STOP,
+
+        /** Reset state indicator.
+         * <p>This value should be used as the return value of the {@link
+         * #eventOccurred eventOccurred} method when the integration should
+         * go on after the event ending the current step, with a new state
+         * vector (which will be retrieved thanks to the {@link #resetState
+         * resetState} method).</p>
+         */
+        RESET_STATE,
+
+        /** Reset derivatives indicator.
+         * <p>This value should be used as the return value of the {@link
+         * #eventOccurred eventOccurred} method when the integration should
+         * go on after the event ending the current step, with a new 
derivatives
+         * vector (which will be retrieved thanks to the {@link
+         * 
org.apache.commons.math.ode.FirstOrderDifferentialEquations#computeDerivatives}
+         * method).</p>
+         */
+        RESET_DERIVATIVES,
+
+        /** Continue indicator.
+         * <p>This value should be used as the return value of the {@link
+         * #eventOccurred eventOccurred} method when the integration should go
+         * on after the event ending the current step.</p>
+         */
+        CONTINUE;
 
-  /** Reset derivatives indicator.
-   * <p>This value should be used as the return value of the {@link
-   * #eventOccurred eventOccurred} method when the integration should
-   * go on after the event ending the current step, with a new derivatives
-   * vector (which will be retrieved thanks to the {@link
-   * 
org.apache.commons.math.ode.FirstOrderDifferentialEquations#computeDerivatives}
-   * method).</p>
-   */
-  int RESET_DERIVATIVES = 2;
-
-  /** Continue indicator.
-   * <p>This value should be used as the return value of the {@link
-   * #eventOccurred eventOccurred} method when the integration should go
-   * on after the event ending the current step.</p>
-   */
-  int CONTINUE = 3;
+    }
 
   /** Compute the value of the switching function.
 
@@ -158,7 +163,7 @@ public interface EventHandler  {
    * value must be one of {@link #STOP}, {@link #RESET_STATE},
    * {@link #RESET_DERIVATIVES} or {@link #CONTINUE}
    */
-  int eventOccurred(double t, double[] y, boolean increasing);
+  Action eventOccurred(double t, double[] y, boolean increasing);
 
   /** Reset the state prior to continue the integration.
 

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java?rev=1175379&r1=1175378&r2=1175379&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java
 Sun Sep 25 12:39:09 2011
@@ -24,6 +24,7 @@ import org.apache.commons.math.analysis.
 import org.apache.commons.math.analysis.solvers.UnivariateRealSolver;
 import org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils;
 import org.apache.commons.math.exception.ConvergenceException;
+import org.apache.commons.math.ode.events.EventHandler;
 import org.apache.commons.math.ode.sampling.StepInterpolator;
 import org.apache.commons.math.util.FastMath;
 
@@ -81,7 +82,7 @@ public class EventState {
     private boolean increasing;
 
     /** Next action indicator. */
-    private int nextAction;
+    private EventHandler.Action nextAction;
 
     /** Root-finding algorithm to use to detect state events. */
     private final UnivariateRealSolver solver;
@@ -113,7 +114,7 @@ public class EventState {
         pendingEventTime  = Double.NaN;
         previousEventTime = Double.NaN;
         increasing        = true;
-        nextAction        = EventHandler.CONTINUE;
+        nextAction        = EventHandler.Action.CONTINUE;
 
     }
 
@@ -304,7 +305,7 @@ public class EventState {
             nextAction        = handler.eventOccurred(t, y, !(increasing ^ 
forward));
         } else {
             g0Positive = g0 >= 0;
-            nextAction = EventHandler.CONTINUE;
+            nextAction = EventHandler.Action.CONTINUE;
         }
     }
 
@@ -313,7 +314,7 @@ public class EventState {
      * @return true if the integration should be stopped
      */
     public boolean stop() {
-        return nextAction == EventHandler.STOP;
+        return nextAction == EventHandler.Action.STOP;
     }
 
     /** Let the event handler reset the state if it wants.
@@ -329,14 +330,14 @@ public class EventState {
             return false;
         }
 
-        if (nextAction == EventHandler.RESET_STATE) {
+        if (nextAction == EventHandler.Action.RESET_STATE) {
             handler.resetState(t, y);
         }
         pendingEvent      = false;
         pendingEventTime  = Double.NaN;
 
-        return (nextAction == EventHandler.RESET_STATE) ||
-               (nextAction == EventHandler.RESET_DERIVATIVES);
+        return (nextAction == EventHandler.Action.RESET_STATE) ||
+               (nextAction == EventHandler.Action.RESET_DERIVATIVES);
 
     }
 

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/TestProblem4.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/TestProblem4.java?rev=1175379&r1=1175378&r2=1175379&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/TestProblem4.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/TestProblem4.java
 Sun Sep 25 12:39:09 2011
@@ -119,10 +119,10 @@ public TestProblem4 copy() {
       return sign * y[0];
     }
 
-    public int eventOccurred(double t, double[] y, boolean increasing) {
+    public Action eventOccurred(double t, double[] y, boolean increasing) {
       // this sign change is needed because the state will be reset soon
       sign = -sign;
-      return EventHandler.RESET_STATE;
+      return Action.RESET_STATE;
     }
 
     public void resetState(double t, double[] y) {
@@ -141,8 +141,8 @@ public TestProblem4 copy() {
       return t - 12.0;
     }
 
-    public int eventOccurred(double t, double[] y, boolean increasing) {
-      return EventHandler.STOP;
+    public Action eventOccurred(double t, double[] y, boolean increasing) {
+      return Action.STOP;
     }
 
     public void resetState(double t, double[] y) {

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java?rev=1175379&r1=1175378&r2=1175379&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java
 Sun Sep 25 12:39:09 2011
@@ -39,8 +39,8 @@ public class EventStateTest {
             public double g(double t, double[] y) {
                 return (t - r1) * (r2 - t);
             }
-            public int eventOccurred(double t, double[] y, boolean increasing) 
{
-                return CONTINUE;
+            public Action eventOccurred(double t, double[] y, boolean 
increasing) {
+                return Action.CONTINUE;
             }
         };
 

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/OverlappingEventsTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/OverlappingEventsTest.java?rev=1175379&r1=1175378&r2=1175379&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/OverlappingEventsTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/OverlappingEventsTest.java
 Sun Sep 25 12:39:09 2011
@@ -142,8 +142,8 @@ public class OverlappingEventsTest imple
         }
 
         /** {@inheritDoc} */
-        public int eventOccurred(double t, double[] y, boolean increasing) {
-            return STOP;
+        public Action eventOccurred(double t, double[] y, boolean increasing) {
+            return Action.STOP;
         }
 
         /** {@inheritDoc} */

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java?rev=1175379&r1=1175378&r2=1175379&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java
 Sun Sep 25 12:39:09 2011
@@ -78,9 +78,9 @@ public class ClassicalRungeKuttaIntegrat
               return t - tEvent;
           }
 
-          public int eventOccurred(double t, double[] y, boolean increasing) {
+          public Action eventOccurred(double t, double[] y, boolean 
increasing) {
               Assert.assertEquals(tEvent, t, 5.0e-6);
-              return CONTINUE;
+              return Action.CONTINUE;
           }
       }, Double.POSITIVE_INFINITY, 1.0e-20, 100);
       finalT = integrator.integrate(ode, t0, y0, tEvent + 120, y);

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java?rev=1175379&r1=1175378&r2=1175379&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
 Sun Sep 25 12:39:09 2011
@@ -80,9 +80,9 @@ public class DormandPrince853IntegratorT
               return t - tEvent;
           }
 
-          public int eventOccurred(double t, double[] y, boolean increasing) {
+          public Action eventOccurred(double t, double[] y, boolean 
increasing) {
               Assert.assertEquals(tEvent, t, 5.0e-6);
-              return CONTINUE;
+              return Action.CONTINUE;
           }
       }, Double.POSITIVE_INFINITY, 1.0e-20, 100);
       finalT = integrator.integrate(ode, t0, y0, tEvent + 120, y);

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java?rev=1175379&r1=1175378&r2=1175379&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java
 Sun Sep 25 12:39:09 2011
@@ -202,8 +202,8 @@ public class HighamHall54IntegratorTest 
       integ.addStepHandler(handler);
 
       integ.addEventHandler(new EventHandler() {
-        public int eventOccurred(double t, double[] y, boolean increasing) {
-          return EventHandler.CONTINUE;
+        public Action eventOccurred(double t, double[] y, boolean increasing) {
+          return Action.CONTINUE;
         }
         public double g(double t, double[] y) {
           double middle = (pb.getInitialTime() + pb.getFinalTime()) / 2;
@@ -246,8 +246,8 @@ public class HighamHall54IntegratorTest 
     integ.addStepHandler(handler);
 
     integ.addEventHandler(new EventHandler() {
-      public int eventOccurred(double t, double[] y, boolean increasing) {
-        return EventHandler.CONTINUE;
+      public Action eventOccurred(double t, double[] y, boolean increasing) {
+        return Action.CONTINUE;
       }
       public double g(double t, double[] y) {
         double middle = (pb.getInitialTime() + pb.getFinalTime()) / 2;

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/StepProblem.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/StepProblem.java?rev=1175379&r1=1175378&r2=1175379&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/StepProblem.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/StepProblem.java
 Sun Sep 25 12:39:09 2011
@@ -43,9 +43,9 @@ public class StepProblem
     this.rate = rate;
   }
 
-  public int eventOccurred(double t, double[] y, boolean increasing) {
+  public Action eventOccurred(double t, double[] y, boolean increasing) {
     setRate(rateAfter);
-    return RESET_DERIVATIVES;
+    return Action.RESET_DERIVATIVES;
   }
 
   public double g(double t, double[] y) {


Reply via email to