/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2017-2018 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.BasicObjects;

import java.net.URI;
import java.util.ArrayList;

import com.jaamsim.input.ExpError;
import com.jaamsim.input.ExpResult;
import com.jaamsim.input.FileInput;
import com.jaamsim.input.Output;

public class FileToVector extends FileToArray {

	ArrayList<ExpResult> value;

	public FileToVector() {
		value = new ArrayList<>();
	}

	@Override
	protected void setValueForURI(URI uri, double simTime) {
		value = getVectorForURI(uri, simTime);
	}

	@Override
	protected void clearValue() {
		value = new ArrayList<>();
	}

	private ArrayList<ExpResult> getVectorForURI(URI uri, double simTime) {
		ArrayList<ArrayList<String>> tokens = FileInput.getTokensFromURI(uri);
		int n = 0;
		for (ArrayList<String> record : tokens) {
			n += record.size();
		}
		ArrayList<ExpResult> ret = new ArrayList<>(n);
		for (ArrayList<String> record : tokens) {
			ArrayList<ExpResult> expRecord = getExpResultList(record, simTime);
			ret.addAll(expRecord);
		}
		return ret;
	}

	/**
	 * Sets the data for the FileToVector directly from a Java data structure, without the use
	 * of the DataFile input which can be left blank. The list input can contain the following
	 * Java classes and their sub-classes: Double, Integer, String, Entity, List, Map, and Array.
	 * @param list - List of Java objects containing the input data.
	 * @throws Exception
	 */
	public void setValue(ArrayList<Object> list) throws ExpError {
		value = getExpResultList(list);
	}

	@Output(name = "Value",
	 description = "A vector containing the data from the input file.",
	    sequence = 1)
	public ArrayList<ExpResult> getValue(double simTime) {
		return value;
	}

}

@@ -764,16 +764,57 @@
 pError;%0A
+import com.jaamsim.input.ExpCollections;%0A
 import c
@@ -909,16 +909,60 @@
 .Output;
+%0Aimport com.jaamsim.units.DimensionlessUnit;
 %0A%0Apublic
@@ -1005,26 +1005,16 @@
 ray %7B%0A%0A%09
-ArrayList%3C
 ExpResul
@@ -1014,17 +1014,16 @@
 xpResult
-%3E
  value;%0A
@@ -1050,39 +1050,26 @@
 r() %7B%0A%09%09
-value = new ArrayList%3C%3E
+clearValue
 ();%0A%09%7D%0A%0A
@@ -1230,32 +1230,129 @@
 %7B%0A%09%09
-value = new ArrayList%3C%3E(
+ArrayList%3CExpResult%3E resList = new ArrayList%3C%3E();%0A%09%09value = ExpCollections.getCollection(resList, DimensionlessUnit.class
 );%0A%09
@@ -1363,26 +1363,16 @@
 private 
-ArrayList%3C
 ExpResul
@@ -1368,25 +1368,24 @@
 te ExpResult
-%3E
  getVectorFo
@@ -1776,19 +1776,74 @@
 %09return 
-ret
+ExpCollections.getCollection(ret, DimensionlessUnit.class)
 ;%0A%09%7D%0A%0A%09/
@@ -2287,37 +2287,134 @@
 %7B%0A%09%09
-value = getExpResultList(list
+ArrayList%3CExpResult%3E resList = getExpResultList(list);%0A%09%09value = ExpCollections.getCollection(resList, DimensionlessUnit.class
 );%0A%09
@@ -2537,26 +2537,16 @@
 %09public 
-ArrayList%3C
 ExpResul
@@ -2546,17 +2546,16 @@
 xpResult
-%3E
  getValu

convert FileToVector to return an ExpResult