Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8")); //$NON-NLS-1$
try
{
CSVPrinter printer = new CSVPrinter(writer);
printer.setStrategy(STRATEGY);
// write header
printer.print(Messages.CSVColumn_Date);
for (Security security : export)
printer.print(security.getExternalIdentifier());
printer.println();
// stop if no securities exist
if (earliestDate == null)
return;
// write quotes
Calendar cal = Calendar.getInstance();
cal.setTime(earliestDate);
Date today = Dates.today();
while (cal.getTimeInMillis() <= today.getTime())
{
// check if any quotes exist for that day at all
int[] indices = new int[export.size()];
int ii = 0;
for (Security security : export)
{
SecurityPrice p = new SecurityPrice(cal.getTime(), 0);
indices[ii] = Collections.binarySearch(security.getPrices(), p);
ii++;
}
boolean hasValues = false;
for (ii = 0; ii < indices.length && !hasValues; ii++)
hasValues = indices[ii] >= 0;
if (hasValues)
{
printer.print(Values.Date.format(cal.getTime()));
for (ii = 0; ii < indices.length; ii++)
{
if (indices[ii] < 0)
printer.print(""); //$NON-NLS-1$
else
printer.print(Values.Quote.format(export.get(ii).getPrices().get(indices[ii]).getValue()));
}
printer.println();
}
cal.add(Calendar.DATE, 1);
}