/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package etomica.listener;

import etomica.action.IAction;
import etomica.integrator.IntegratorListener;
import etomica.integrator.IntegratorEvent;

public class IntegratorListenerAction implements IntegratorListener {

    private IAction action;
    private int interval;
    private int intervalCount;
    
    public IntegratorListenerAction(IAction a) {
        this(a, 1);
    }
    
    public IntegratorListenerAction(IAction a, int interval) {
        action = a;
        this.interval = interval;
        intervalCount = 0;
    }
    
    public void integratorInitialized(IntegratorEvent e) {
        if(intervalCount >= interval) {
            
        }
    }
    
    public void integratorStepStarted(IntegratorEvent e) {
        if(++intervalCount >= interval) {
            
        }
        
    }
    
    public void integratorStepFinished(IntegratorEvent e) {
        if(intervalCount >= interval) {
            intervalCount = 0;
            action.actionPerformed();
        }
    }
    
    public void setInterval(int i) {
        interval = i;
    }
    
    public int getInterval() {
        return interval;
    }
    
    public IAction getAction() {
        return action;
    }
    
}

@@ -293,24 +293,21 @@
 tegrator
-Listener
+Event
 ;%0Aimport
@@ -340,23 +340,169 @@
 ator
-Event;%0A
+Listener;%0A%0A/**%0A * An IntegratorListener that performs an action after every integrator step,%0A * optionally with a given interval of integrator steps.%0A */
 %0Apublic 
 clas
@@ -497,16 +497,22 @@
 %0Apublic 
+final 
 class In
@@ -579,16 +579,22 @@
 private 
+final 
 IAction 
@@ -658,20 +658,16 @@
 lCount;%0A
-    
 %0A    pub
@@ -726,36 +726,32 @@
 is(a, 1);%0A    %7D%0A
-    
 %0A    public Inte
@@ -877,36 +877,32 @@
 ount = 0;%0A    %7D%0A
-    
 %0A    public void
@@ -949,81 +949,14 @@
 ) %7B%0A
-        if(intervalCount %3E= interval) %7B%0A            %0A        %7D%0A
     %7D%0A
-    
 %0A   
@@ -1019,19 +1019,16 @@
         
-if(
 ++interv
@@ -1038,66 +1038,16 @@
 ount
- %3E= interval) %7B%0A            %0A        %7D%0A        
+;
 %0A    %7D%0A
-    
 %0A   
@@ -1113,16 +1113,17 @@
       if
+ 
 (interva
@@ -1225,28 +1225,24 @@
     %7D%0A    %7D%0A
-    
 %0A    public 
@@ -1245,14 +1245,13 @@
 lic 
-void s
+int g
 etIn
@@ -1257,21 +1257,16 @@
 nterval(
-int i
 ) %7B%0A    
@@ -1269,24 +1269,31 @@
         
+return 
 interval
  = i;%0A  
@@ -1288,20 +1288,16 @@
 rval
- = i
 ;%0A    %7D%0A
     
@@ -1284,36 +1284,32 @@
 interval;%0A    %7D%0A
-    
 %0A    public int 
@@ -1296,37 +1296,38 @@
   %7D%0A%0A    public 
-int g
+void s
 etInterval() %7B%0A 
@@ -1313,32 +1313,37 @@
 oid setInterval(
+int i
 ) %7B%0A        retu
@@ -1334,39 +1334,32 @@
 ) %7B%0A        
-return 
 interval
 ;%0A    %7D%0A    
@@ -1346,24 +1346,28 @@
 interval
+ = i
 ;%0A    %7D%0A
     %0A   
@@ -1358,20 +1358,16 @@
 ;%0A    %7D%0A
-    
 %0A    pub
@@ -1421,15 +1421,11 @@
 ;%0A    %7D%0A
-    
 %0A%7D%0A

Clean up IntegratorListenerAction