package org.finra.datagenerator.scxml;

import java.util.ArrayList;
import org.apache.commons.scxml.SCXMLListener;
import org.apache.commons.scxml.model.Transition;
import org.apache.commons.scxml.model.TransitionTarget;
import org.apache.log4j.Logger;

public class StateMachineListener implements SCXMLListener {

    private final ArrayList<TransitionTarget> states = new ArrayList<TransitionTarget>();
    private final ArrayList<Transition> transitions = new ArrayList<Transition>();
    private TransitionTarget currentState = null;
    private TransitionTarget lastState = null;
    private Transition lastTransition = null;
    private static final Logger log = Logger.getLogger(StateMachineListener.class);
    private static boolean isDebugEnabled = false;

    public void reset() {
        if (isDebugEnabled) {
            log.debug("RESET");
        }
        states.clear();
        transitions.clear();
        currentState = null;
        lastState = null;
        lastTransition = null;
    }

    public Transition getLastTransition() {
        return lastTransition;
    }

    public TransitionTarget getCurrentState() {
        return currentState;
    }

    public TransitionTarget getLastState() {
        return lastState;
    }

    public ArrayList<TransitionTarget> getStatesList() {
        return states;
    }

    public ArrayList<Transition> getTransitionList() {
        return transitions;
    }

    @Override
    public void onEntry(TransitionTarget state) {
        if (isDebugEnabled) {
            log.debug("Entering state:" + state.getId());
        }
        currentState = state;
        states.add(state);
    }

    @Override
    public void onExit(TransitionTarget state) {
        if (isDebugEnabled) {
            log.debug("Exiting state:" + state.getId());
        }
        lastState = state;
    }

    @Override
    public void onTransition(TransitionTarget from, TransitionTarget to, Transition transition) {
        if (isDebugEnabled) {
            log.debug("Transitioning between:" + from.getId() + " and " + to.getId() + " using event "
                    + transition.getEvent());
        }
        lastTransition = transition;
        transitions.add(transition);
    }

}

@@ -37,36 +37,8 @@
 l;%0A%0A
-import java.util.ArrayList;%0A
 impo
@@ -80,16 +80,16 @@
 stener;%0A
+
 import o
@@ -283,182 +283,8 @@
 er %7B
-%0A%0A    private final ArrayList%3CTransitionTarget%3E states = new ArrayList%3CTransitionTarget%3E();%0A    private final ArrayList%3CTransition%3E transitions = new ArrayList%3CTransition%3E();
 %0A   
@@ -526,16 +526,22 @@
  static 
+final 
 boolean 
@@ -667,61 +667,8 @@
   %7D%0A
-        states.clear();%0A        transitions.clear();%0A
     
@@ -1004,185 +1004,8 @@
  %7D%0A%0A
-    public ArrayList%3CTransitionTarget%3E getStatesList() %7B%0A        return states;%0A    %7D%0A%0A    public ArrayList%3CTransition%3E getTransitionList() %7B%0A        return transitions;%0A    %7D%0A%0A
     
@@ -1196,35 +1196,8 @@
 te;%0A
-        states.add(state);%0A
     
@@ -1735,50 +1735,12 @@
 on;%0A
-        transitions.add(transition);%0A
     %7D%0A
-%0A
 %7D%0A

Remove the states list. Was causing a memory leak