package cse308.swift.shared.beans; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import org.apache.log4j.Logger; import cse308.swift.server.quotequerier.YahooQuoteQuerier; public class QuoteHistoricalData { /** * Instance of the Logger Object */ static Logger logger = Logger.getLogger(QuoteHistoricalData.class.getName()); private ArrayList headers = new ArrayList(); private ArrayList historicalData = new ArrayList(); private String quote; private Date startDate; private Date endDate; private String queryURL; public QuoteHistoricalData(String quote, Date startDate, Date endDate, String queryURL, java.util.List csvData) { this.quote = quote; this.startDate = startDate; this.endDate = endDate; this.queryURL = queryURL; headers = new ArrayList(Arrays.asList(csvData.get(0))); for(int i = 1; i < csvData.size(); i++) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date historicalDate = null; try { historicalDate = dateFormat.parse(csvData.get(i)[0]); } catch (ParseException e) { logger.warn("Could Not Parse the Historical Date for Quote: " + quote); } Double openValue = Double.parseDouble(csvData.get(i)[1]); Double highValue = Double.parseDouble(csvData.get(i)[2]); Double lowValue = Double.parseDouble(csvData.get(i)[3]); Double closeValue = Double.parseDouble(csvData.get(i)[4]); long volume = Long.parseLong(csvData.get(i)[5]); Double adjustedCloseValue = Double.parseDouble(csvData.get(i)[6]); historicalData.add(new QuoteHistoricalDataElement(historicalDate, openValue, highValue, lowValue, closeValue, volume, adjustedCloseValue)); } } public ArrayList getHeaders() { return headers; } public ArrayList getHistoricalData() { return historicalData; } public String getQuote() { return quote; } public Date getStartDate() { return startDate; } public Date getEndDate() { return endDate; } public String getQueryURL() { return queryURL; } private class QuoteHistoricalDataElement { private Date historicalDate; private double openValue; private double highValue; private double lowValue; private double closeValue; private long volume; private double adjustedCloseValue; private QuoteHistoricalDataElement(Date historicalDate, double openValue, double highValue, double lowValue, double closeValue, long volume, double adjustedCloseValue) { this.historicalDate = historicalDate; this.openValue = openValue; this.highValue = highValue; this.lowValue = lowValue; this.closeValue = closeValue; this.volume = volume; this.adjustedCloseValue = adjustedCloseValue; } public Date getHistoricalDate() { return historicalDate; } public double getOpenValue() { return openValue; } public double getHighValue() { return highValue; } public double getLowValue() { return lowValue; } public double getCloseValue() { return closeValue; } public long getVolume() { return volume; } public double getAdjustedCloseValue() { return adjustedCloseValue; } } }