// Path: cas-control/src/main/java/com/ghjansen/cas/control/simulation/SimulationController.java
// public abstract class SimulationController<I extends Simulation, M extends SimulationBuilder> {
// 
//     private final I simulation;
//     private final ExecutorService executor;
//     private final Task completeTask;
//     private final Task iterationTask;
//     private final Task unitTask;
//     private final TaskNotification notification;
// 
//     public SimulationController(M simulationBuilder, TaskNotification notification) throws SimulationBuilderException {
//         this.simulation = (I) simulationBuilder.build();
//         this.completeTask = new CompleteTask(this);
//         this.iterationTask = new IterationTask(this);
//         this.unitTask = new UnitTask(this);
//         this.notification = notification;
//         this.executor = Executors.newCachedThreadPool();
//     }
// 
//     public void startCompleteTask() throws SimulationAlreadyActiveException {
//         if (this.simulation.isActive()) {
//             throw new SimulationAlreadyActiveException();
//         }
//         executor.execute(this.completeTask);
//     }
// 
//     public void startIterationTask() throws SimulationAlreadyActiveException {
//         if (this.simulation.isActive()) {
//             throw new SimulationAlreadyActiveException();
//         }
//         executor.execute(this.iterationTask);
//     }
// 
//     public void startUnitTask() throws SimulationAlreadyActiveException {
//         if (this.simulation.isActive()) {
//             throw new SimulationAlreadyActiveException();
//         }
//         this.unitTask.run();
//     }
// 
//     public void stop() {
//         this.simulation.setActive(false);
//     }
// 
//     public I getSimulation() {
//         return simulation;
//     }
// 
//     public void processThreadInterruption(Throwable e) {
//         if (notification != null) {
//             if (e.getClass().equals(TimeLimitReachedException.class)) {
//                 notification.timeLimitReached(e);
//             } else {
//                 notification.generic(e);
//             }
//         }
//     }
// 
// }
// 
// Path: cas-core/src/main/java/com/ghjansen/cas/core/exception/InvalidCombinationException.java
// public class InvalidCombinationException extends Exception {
// 
//     /**
//      * Serialization management
//      */
//     private static final long serialVersionUID = 884762124844706448L;
// 
// }
// 
// Path: cas-core/src/main/java/com/ghjansen/cas/core/exception/InvalidStateException.java
// public class InvalidStateException extends Exception {
// 
//     /**
//      * Serialization management
//      */
//     private static final long serialVersionUID = -7435119307025647318L;
// 
// }
// 
// Path: cas-core/src/main/java/com/ghjansen/cas/core/exception/InvalidTransitionException.java
// public class InvalidTransitionException extends Exception {
// 
//     /**
//      * Serialization management
//      */
//     private static final long serialVersionUID = 1848434169756515614L;
// 
// }
// 
// Path: cas-core/src/main/java/com/ghjansen/cas/core/exception/TimeLimitReachedException.java
// public class TimeLimitReachedException extends Exception {
// 
//     /**
//      * Serialization management
//      */
//     private static final long serialVersionUID = -6359890788325087840L;
// 
// }


import com.ghjansen.cas.control.simulation.SimulationController;
import com.ghjansen.cas.core.exception.InvalidCombinationException;
import com.ghjansen.cas.core.exception.InvalidStateException;
import com.ghjansen.cas.core.exception.InvalidTransitionException;
import com.ghjansen.cas.core.exception.TimeLimitReachedException;
/*
 * CAS - Cellular Automata Simulator
 * Copyright (C) 2016  Guilherme Humberto Jansen
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.ghjansen.cas.control.task;


/**
 * @author Guilherme Humberto Jansen (contact.ghjansen@gmail.com)
 */
public class CompleteTask extends Task {

    public CompleteTask(SimulationController simulationController) {
        super(simulationController);
    }

    public void run() {
        try {
            this.simulationController.getSimulation().simulateComplete();
        } catch (InvalidStateException e) {
            this.simulationController.processThreadInterruption(e);
        } catch (InvalidCombinationException e) {
            this.simulationController.processThreadInterruption(e);
        } catch (InvalidTransitionException e) {
            this.simulationController.processThreadInterruption(e);
        } catch (TimeLimitReachedException e) {
// Path: cas-control/src/main/java/com/ghjansen/cas/control/simulation/SimulationController.java
// public abstract class SimulationController<I extends Simulation, M extends SimulationBuilder> {
// 
//     private final I simulation;
//     private final ExecutorService executor;
//     private final Task completeTask;
//     private final Task iterationTask;
//     private final Task unitTask;
//     private final TaskNotification notification;
// 
//     public SimulationController(M simulationBuilder, TaskNotification notification) throws SimulationBuilderException {
//         this.simulation = (I) simulationBuilder.build();
//         this.completeTask = new CompleteTask(this);
//         this.iterationTask = new IterationTask(this);
//         this.unitTask = new UnitTask(this);
//         this.notification = notification;
//         this.executor = Executors.newCachedThreadPool();
//     }
// 
//     public void startCompleteTask() throws SimulationAlreadyActiveException {
//         if (this.simulation.isActive()) {
//             throw new SimulationAlreadyActiveException();
//         }
//         executor.execute(this.completeTask);
//     }
// 
//     public void startIterationTask() throws SimulationAlreadyActiveException {
//         if (this.simulation.isActive()) {
//             throw new SimulationAlreadyActiveException();
//         }
//         executor.execute(this.iterationTask);
//     }
// 
//     public void startUnitTask() throws SimulationAlreadyActiveException {
//         if (this.simulation.isActive()) {
//             throw new SimulationAlreadyActiveException();
//         }
//         this.unitTask.run();
//     }
// 
//     public void stop() {
//         this.simulation.setActive(false);
//     }
// 
//     public I getSimulation() {
//         return simulation;
//     }
// 
//     public void processThreadInterruption(Throwable e) {
//         if (notification != null) {
//             if (e.getClass().equals(TimeLimitReachedException.class)) {
//                 notification.timeLimitReached(e);
//             } else {
//                 notification.generic(e);
//             }
//         }
//     }
// 
// }
// 
// Path: cas-core/src/main/java/com/ghjansen/cas/core/exception/InvalidCombinationException.java
// public class InvalidCombinationException extends Exception {
// 
//     /**
//      * Serialization management
//      */
//     private static final long serialVersionUID = 884762124844706448L;
// 
// }
// 
// Path: cas-core/src/main/java/com/ghjansen/cas/core/exception/InvalidStateException.java
// public class InvalidStateException extends Exception {
// 
//     /**
//      * Serialization management
//      */
//     private static final long serialVersionUID = -7435119307025647318L;
// 
// }
// 
// Path: cas-core/src/main/java/com/ghjansen/cas/core/exception/InvalidTransitionException.java
// public class InvalidTransitionException extends Exception {
// 
//     /**
//      * Serialization management
//      */
//     private static final long serialVersionUID = 1848434169756515614L;
// 
// }
// 
// Path: cas-core/src/main/java/com/ghjansen/cas/core/exception/TimeLimitReachedException.java
// public class TimeLimitReachedException extends Exception {
// 
//     /**
//      * Serialization management
//      */
//     private static final long serialVersionUID = -6359890788325087840L;
// 
// }


// Path: cas-control/src/main/java/com/ghjansen/cas/control/task/CompleteTask.java
import com.ghjansen.cas.control.simulation.SimulationController;
import com.ghjansen.cas.core.exception.InvalidCombinationException;
import com.ghjansen.cas.core.exception.InvalidStateException;
import com.ghjansen.cas.core.exception.InvalidTransitionException;
import com.ghjansen.cas.core.exception.TimeLimitReachedException;

/*
 * CAS - Cellular Automata Simulator
 * Copyright (C) 2016  Guilherme Humberto Jansen
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.ghjansen.cas.control.task;


/**
 * @author Guilherme Humberto Jansen (contact.ghjansen@gmail.com)
 */
public class CompleteTask extends Task {

    public CompleteTask(SimulationController simulationController) {
        super(simulationController);
    }

    public void run() {
        try {
            this.simulationController.getSimulation().simulateComplete();
        } catch (InvalidStateException e) {
            this.simulationController.processThreadInterruption(e);
        } catch (InvalidCombinationException e) {
            this.simulationController.processThreadInterruption(e);
        } catch (InvalidTransitionException e) {
            this.simulationController.processThreadInterruption(e);
        } catch (TimeLimitReachedException e) {
            this.simulationController.processThreadInterruption(e);