/*
 *  Draco Econometrics
 *  Copyright (C) 2008-2009 Approximatrix, LLC
 *  http://www.approximatrix.com
 *  
 *  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.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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;	
	}
	
}
