package com.henrypump.poc;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * Created by patrickjmcd on 2/1/17.
 */
public class Simulation {

    private double[] position = new double[1500];
    private double[] load = new double[1500];
    private int lastFilledIndex = 0;

    private void parseCSV(String filename){
        BufferedReader br = null;
        String line = "";
        String cvsSplitBy = ",";
        int lineNum = 0;
        try {
            br = new BufferedReader(new FileReader(filename));
            while ((line = br.readLine()) != null) {
                // use comma as separator
                String[] splitLine = line.split(cvsSplitBy);
                position[lineNum] = Double.parseDouble(splitLine[0]);
                load[lineNum] = Double.parseDouble(splitLine[1]);
                lineNum++;
            }


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

            if (br != null) {
                lastFilledIndex = lineNum - 1;
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public double getPositionAtIndex(int ind){
        return position[ind];
    }

    public double getLoadAtIndex(int ind){
        return load[ind];
    }

    public int getLastFilledIndex() {return lastFilledIndex; }

    Simulation(String simFilePath){
        parseCSV(simFilePath);
    }

    public static void main(String[] args){
        Simulation sim = new Simulation(args[0]);
        for(int i = 0; i <= sim.lastFilledIndex; i++){
            System.out.println("Position: " + sim.getPositionAtIndex(i) + ", Load: "+ sim.getLoadAtIndex(i));
        }
    }




}
