/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2013 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 General Public License for more details.
 */
package com.jaamsim.BasicObjects;

import com.sandwell.JavaSimulation.EntityInput;
import com.sandwell.JavaSimulation.InputErrorException;
import com.sandwell.JavaSimulation.Keyword;
import com.sandwell.JavaSimulation3D.DisplayEntity;

/**
 * LinkedComponents are used to form a chain of components that process DisplayEntities that pass through the system.
 * Sub-classes for EntityGenerator, Server, and EntitySink.
 */
public class LinkedComponent extends DisplayEntity {

	@Keyword(description = "The next object to which the processed DisplayEntity is passed.",
	         example = "EntityGenerator1 NextComponent { Server1 }")
	protected final EntityInput<LinkedComponent> nextComponentInput;

	int numberProcessed; // Number of entities processed by this component

	{
		nextComponentInput = new EntityInput<LinkedComponent>( LinkedComponent.class, "NextComponent", "Key Inputs", null);
		this.addInput( nextComponentInput, true);
	}

	public LinkedComponent() {
	}

	@Override
	public void validate() {
		super.validate();

		// Confirm that the next entity in the chain has been specified
		if( ! nextComponentInput.getHidden() &&	getNextComponent() == null ) {
			throw new InputErrorException( "The keyword NextEntity must be set." );
		}
	}

	@Override
	public void earlyInit() {
		super.earlyInit();

		numberProcessed = 0;
	}


	/**
	 * MUST BE OVERWRITTEN BY EACH SUB-CLASS
	 * Receive a DisplayEntity from the upstream LinkedEntity.
	 * @param ent = the DisplayEntity that is received.
	 */
	public void addDisplayEntity( DisplayEntity ent ) {
	}

	public LinkedComponent getNextComponent(){
		return nextComponentInput.getValue();
	}

}

@@ -1024,16 +1024,25 @@
 %0Apublic 
+abstract 
 class Li
@@ -1079,16 +1079,16 @@
 ntity %7B%0A
-
 %0A%09@Keywo
@@ -1207,16 +1207,17 @@
 enerator
+-
 1 NextCo
@@ -1232,16 +1232,17 @@
 %7B Server
+-
 1 %7D%22)%0A%09p
@@ -1552,40 +1552,8 @@
 %09%7D%0A%0A
-%09public LinkedComponent() %7B%0A%09%7D%0A%0A
 %09@Ov
@@ -1714,20 +1714,17 @@
 en() &&%09
-getN
+n
 extCompo
@@ -1727,16 +1727,30 @@
 omponent
+Input.getValue
 () == nu
@@ -1930,174 +1930,8 @@
 %09%7D%0A%0A
-%0A%09/**%0A%09 * MUST BE OVERWRITTEN BY EACH SUB-CLASS%0A%09 * Receive a DisplayEntity from the upstream LinkedEntity.%0A%09 * @param ent = the DisplayEntity that is received.%0A%09 */%0A
 %09pub

Make LinkedComponent abstract and perform some cleanup