/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2014 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.Graphics.DisplayEntity;
import com.jaamsim.basicsim.ErrorException;
import com.jaamsim.input.ExpError;
import com.jaamsim.input.ExpEvaluator;
import com.jaamsim.input.ExpressionInput;
import com.jaamsim.input.Keyword;
import com.jaamsim.input.Output;
import com.jaamsim.units.DimensionlessUnit;

public class ExpressionEntity extends DisplayEntity {
	@Keyword(description = "The variable for which statistics will be collected.",
	         example = "Statistics1  SampleValue { 'this.obj.Attrib1' }")
	private final ExpressionInput sampleValue;

	{
		sampleValue = new ExpressionInput("Expression", "Key Inputs", null);
		sampleValue.setEntity(this);
		this.addInput(sampleValue);
	}

	public ExpressionEntity() {}

	@Output(name = "Value",
	 description = "The evaluated value of the expression.",
	    unitType = DimensionlessUnit.class,
	  reportable = true)
	public double evaluateExpression(double simTime) {
		if (sampleValue.getValue() == null)
			return 0.0d;

		try {
			// Evaluate the expression
			double ret = ExpEvaluator.evaluateExpression(sampleValue.getValue(), simTime, this).value;
			return ret;
		} catch(ExpError e) {
			throw new ErrorException(e);
		}
	}
}

@@ -999,16 +999,17 @@
 ntity %7B%0A
+%0A
 %09@Keywor
@@ -1033,128 +1033,111 @@
 The 
-variable for which statistics will be collected.%22,%0A%09         example = %22Statistics1  SampleValue %7B 'this.obj.Attrib1' %7D%22
+expression to be evaluated.%22,%0A%09         exampleList = %7B%22'%5BQueue1%5D.QueueLength + %5BQueue2%5D.QueueLength'%22%7D
 )%0A%09p
@@ -1253,16 +1253,16 @@
  null);%0A
-
 %09%09sample
@@ -1284,16 +1284,49 @@
 (this);%0A
+%09%09sampleValue.setRequired(true);%0A
 %09%09this.a

correct keyword description for ExpressionEntity and make it a required input