/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2013 Ausenco Engineering Canada Inc.
 * Copyright (C) 2020 JaamSim Software 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.Samples;

import java.util.ArrayList;

import com.jaamsim.basicsim.JaamSimModel;
import com.jaamsim.input.Input;
import com.jaamsim.units.DimensionlessUnit;
import com.jaamsim.units.Unit;

public class SampleConstant implements SampleProvider {
	private Class<? extends Unit> unitType;
	private final double val;

	public SampleConstant(Class<? extends Unit> unitType, double val) {
		this.unitType = unitType;
		this.val = val;
	}

	public SampleConstant(double val) {
		this(DimensionlessUnit.class, val);
	}

	void setUnitType(Class<? extends Unit> ut) {
		unitType = ut;
	}

	@Override
	public Class<? extends Unit> getUnitType() {
		return unitType;
	}

	@Override
	public double getNextSample(double simTime) {
		return val;
	}

	@Override
	public double getMeanValue(double simTime) {
		return val;
	}

	@Override
	public double getMinValue() {
		return val;
	}

	@Override
	public double getMaxValue() {
		return val;
	}

	public String getValueString(JaamSimModel simModel) {
		StringBuilder tmp = new StringBuilder();
		tmp.append(Double.toString(val/simModel.getDisplayedUnitFactor(unitType)));
		if (unitType != DimensionlessUnit.class)
			tmp.append(Input.SEPARATOR).append(simModel.getDisplayedUnit(unitType));
		return tmp.toString();
	}

	@Override
	public String toString() {
		StringBuilder tmp = new StringBuilder();
		tmp.append(Double.toString(val));
		if (unitType != DimensionlessUnit.class)
			tmp.append(Input.SEPARATOR).append(Unit.getSIUnit(unitType));
		return tmp.toString();
	}

	public ArrayList<String> getTokens() {
		ArrayList<String> list = new ArrayList<>();
		list.add(Double.toString(val));
		if (unitType != DimensionlessUnit.class)
			list.add(Unit.getSIUnit(unitType));
		return list;
	}
}

@@ -999,16 +999,47 @@
 itType;%0A
+%09private boolean integerValue;%0A
 %09private
@@ -1057,16 +1057,16 @@
 le val;%0A
-
 %0A%09public
@@ -1169,24 +1169,48 @@
 .val = val;%0A
+%09%09integerValue = false;%0A
 %09%7D%0A%0A%09public 
@@ -1280,16 +1280,115 @@
 l);%0A%09%7D%0A%0A
+%09public SampleConstant(int val) %7B%0A%09%09this(DimensionlessUnit.class, val);%0A%09%09integerValue = true;%0A%09%7D%0A%0A
 %09void se
@@ -1848,24 +1848,84 @@
 simModel) %7B%0A
+%09%09if (integerValue)%0A%09%09%09return Integer.toString((int) val);%0A%0A
 %09%09StringBuil
@@ -2220,16 +2220,76 @@
 ing() %7B%0A
+%09%09if (integerValue)%0A%09%09%09return Integer.toString((int) val);%0A%0A
 %09%09String
@@ -2536,16 +2536,16 @@
 ens() %7B%0A
-
 %09%09ArrayL
@@ -2582,16 +2582,102 @@
 st%3C%3E();%0A
+%0A%09%09if (integerValue) %7B%0A%09%09%09list.add(Integer.toString((int) val));%0A%09%09%09return list;%0A%09%09%7D%0A%0A
 %09%09list.a

allow a SampleConstant to be specified as a dimensionless integer