/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2014 Ausenco Engineering Canada Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jaamsim.basicsim;

import com.jaamsim.events.EventManager;
import com.jaamsim.events.ProcessTarget;

public class InitModelTarget extends ProcessTarget {
	public InitModelTarget() {}

	@Override
	public String getDescription() {
		return "SimulationInit";
	}

	@Override
	public void process() {

		// Initialise each entity
		for (int i = 0; i < Entity.getAll().size(); i++) {
			Entity.getAll().get(i).earlyInit();
		}

		// Initialise each entity a second time
		for (int i = 0; i < Entity.getAll().size(); i++) {
			Entity.getAll().get(i).lateInit();
		}

		// Start each entity
		double startTime = Simulation.getStartTime();
		for (int i = Entity.getAll().size() - 1; i >= 0; i--) {
			EventManager.scheduleSeconds(startTime, 0, false, new StartUpTarget(Entity.getAll().get(i)), null);
		}

		// Schedule the initialisation period
		if (Simulation.getInitializationTime() > 0.0) {
			double clearTime = startTime + Simulation.getInitializationTime();
			EventManager.scheduleSeconds(clearTime, 5, false, new ClearStatisticsTarget(), null);
		}

		// Schedule the end of the simulation run
		double endTime = Simulation.getEndTime();
		EventManager.scheduleSeconds(endTime, 5, false, new EndModelTarget(), null);

		// Start checking the pause condition
		Simulation.getInstance().doPauseCondition();
	}
}

@@ -997,79 +997,73 @@
 or (
-int i = 0; i %3C Entity.getAll().size(); i++) %7B%0A%09%09%09Entity.getAll().get(i)
+Entity each : Entity.getClonesOfIterator(Entity.class)) %7B%0A%09%09%09each
 .ear
@@ -1130,79 +1130,73 @@
 or (
-int i = 0; i %3C Entity.getAll().size(); i++) %7B%0A%09%09%09Entity.getAll().get(i)
+Entity each : Entity.getClonesOfIterator(Entity.class)) %7B%0A%09%09%09each
 .lat
@@ -1291,15 +1291,21 @@
 or (
-int i =
+Entity each :
  Ent
@@ -1315,37 +1315,38 @@
 .get
-All().size() - 1; i %3E= 0; i--
+ClonesOfIterator(Entity.class)
 ) %7B%0A
@@ -1391,20 +1391,19 @@
 ime, 0, 
-fals
+tru
 e, new S
@@ -1419,30 +1419,12 @@
 get(
-Entity.getAll().get(i)
+each
 ), n

convert initial model target to Iterators