package com.approximatrix.draco.io.builders.plot;

public class SeriesStore {
	public String[] xdata = null;
	public String[] ydata = null;
	public String name = null;
	
	public int color = 0;
	public boolean marker = false;
	public boolean line = false;
	
	public Double[] getXDataDouble() {
		return getDataDouble(xdata);
	}
	
	public Double[] getYDataDouble() {
		return getDataDouble(ydata);
	}
	
	public double[] getXDataPrimitiveDouble() {
		return getDataPrimitiveDouble(xdata);
	}
	
	public double[] getYDataPrimitiveDouble() {
		return getDataPrimitiveDouble(ydata);
	}
	
	public int[] getXDataPrimitiveInteger() {
		return getDataPrimitiveInteger(xdata);
	}
	
	public int[] getYDataPrimitiveInteger() {
		return getDataPrimitiveInteger(ydata);
	}
	
	private int[] getDataPrimitiveInteger(String[] data) {
		if(data == null) return null;
		
		int[] ret = new int[data.length];
		for(int i=0;i<ret.length;i++) {
			try {
				ret[i] = Integer.parseInt(data[i]);
			} catch(NumberFormatException nfe) {
				ret[i] = 0;
			}
		}
		
		return ret;	
	}
	
	private double[] getDataPrimitiveDouble(String[] data) {
		if(data == null) return null;
		
		double[] ret = new double[data.length];
		for(int i=0;i<ret.length;i++) {
			try {
				ret[i] = Double.parseDouble(data[i]);
			} catch(NumberFormatException nfe) {
				ret[i] = 0.0;
			}
		}
		
		return ret;	
	}
	
	private Double[] getDataDouble(String[] data) {
		if(data == null) return null;
		
		Double[] ret = new Double[data.length];
		for(int i=0;i<ret.length;i++) {
			try {
				ret[i] = new Double(data[i]);
			} catch(NumberFormatException nfe) {
				ret[i] = 0.0;
			}
		}
		
		return ret;	
	}
	
}
