/*
 * 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.jaamsim.input.Keyword;
import com.jaamsim.input.Output;
import com.jaamsim.units.DimensionlessUnit;
import com.jaamsim.units.RateUnit;
import com.sandwell.JavaSimulation.EntityInput;
import com.sandwell.JavaSimulation.InputErrorException;
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 abstract 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;

	private int numberAdded;     // Number of entities added to this component from upstream
	private int numberProcessed; // Number of entities processed by this component
	private DisplayEntity receivedEntity; // Entity most recently received by this component

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

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

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

	@Override
	public void earlyInit() {
		super.earlyInit();
		numberAdded = 0;
		numberProcessed = 0;
	}

	public void addDisplayEntity( DisplayEntity ent ) {
		receivedEntity = ent;
		numberAdded++;
	}

	public void sendToNextComponent(DisplayEntity ent) {
		if( nextComponentInput.getValue() != null )
			nextComponentInput.getValue().addDisplayEntity(ent);

		numberProcessed++;
	}

	@Output(name = "obj",
	 description = "The entity that was received most recently.")
	public DisplayEntity getReceivedEntity(double simTime) {
		return receivedEntity;
	}

	@Output(name = "NumberAdded",
	 description = "The number of entities received from upstream.",
	    unitType = DimensionlessUnit.class)
	public Double getNumberAdded(double simTime) {
		return (double)numberAdded;
	}

	@Output(name = "NumberProcessed",
	 description = "The number of entities processed by this component.",
	    unitType = DimensionlessUnit.class)
	public Double getNumberProcessed(double simTime) {
		return (double)numberProcessed;
	}

	@Output(name = "ProcessingRate",
	 description = "The number of entities processed per unit time by this component.",
	    unitType = RateUnit.class)
	public Double getProcessingRate( double simTime) {
		return numberProcessed/simTime;
	}

}

@@ -630,16 +630,131 @@
 jects;%0A%0A
+import java.util.ArrayList;%0A%0Aimport com.jaamsim.Thresholds.Threshold;%0Aimport com.jaamsim.Thresholds.ThresholdUser;%0A
 import c
@@ -779,16 +779,16 @@
 eyword;%0A
-
 import c
@@ -935,24 +935,76 @@
 ntityInput;%0A
+import com.sandwell.JavaSimulation.EntityListInput;%0A
 import com.s
@@ -1346,16 +1346,41 @@
 yEntity 
+implements ThresholdUser 
 %7B%0A%0A%09@Key
@@ -1470,17 +1470,10 @@
 %22,%0A%09
-         
+%09%09
 exam
@@ -1591,16 +1591,252 @@
 Input;%0A%0A
+%09@Keyword(description = %22A list of thresholds that must be satisified for the entity to operate.%22,%0A%09%09%09example = %22EntityGenerator1 OperatingThresholdList %7B Server1 %7D%22)%0A%09protected final EntityListInput%3CThreshold%3E operatingThresholdList;%0A%0A
 %09private
@@ -2246,16 +2246,203 @@
 tInput);
+%0A%0A%09%09operatingThresholdList = new EntityListInput%3CThreshold%3E(Threshold.class, %22OperatingThresholdList%22, %22Key Inputs%22, new ArrayList%3CThreshold%3E());%0A%09%09this.addInput( operatingThresholdList);
 %0A%09%7D%0A%0A%09@O
@@ -2833,20 +2833,173 @@
 ed = 0;%0A
-
 %09%7D%0A%0A
+%09@Override%0A%09public ArrayList%3CThreshold%3E getThresholds() %7B%0A%09%09return operatingThresholdList.getValue();%0A%09%7D%0A%0A%09@Override%0A%09public void thresholdChanged() %7B%7D%0A%0A
 %09public 

Add keyword "OperatingThresholdList" to Basic Objects