use of org.apache.commons.csv.CSVPrinter in project portfolio by buchen.
the class PerformanceIndex method exportTo.
private void exportTo(File file, Predicate<Integer> filter) throws IOException {
CSVStrategy strategy = new CSVStrategy(';', '"', CSVStrategy.COMMENTS_DISABLED, CSVStrategy.ESCAPE_DISABLED, false, false, false, false);
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
CSVPrinter printer = new CSVPrinter(writer);
printer.setStrategy(strategy);
printer.println(new String[] { //
Messages.CSVColumn_Date, //
Messages.CSVColumn_Value, //
Messages.CSVColumn_InboundTransferals, //
Messages.CSVColumn_OutboundTransferals, //
Messages.CSVColumn_DeltaInPercent, Messages.CSVColumn_CumulatedPerformanceInPercent });
for (int ii = 0; ii < totals.length; ii++) {
if (!filter.test(ii))
continue;
printer.print(dates[ii].toString());
printer.print(Values.Amount.format(totals[ii]));
printer.print(Values.Amount.format(inboundTransferals[ii]));
printer.print(Values.Amount.format(outboundTransferals[ii]));
printer.print(Values.Percent.format(delta[ii]));
printer.print(Values.Percent.format(accumulated[ii]));
printer.println();
}
}
}
use of org.apache.commons.csv.CSVPrinter in project portfolio by buchen.
the class TreeViewerCSVExporter method writeToFile.
@Override
protected void writeToFile(File file) throws IOException {
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
CSVPrinter printer = new CSVPrinter(writer);
printer.setStrategy(STRATEGY);
ITreeContentProvider provider = (ITreeContentProvider) viewer.getContentProvider();
int depth = depth(provider);
int columnCount = viewer.getTree().getColumnCount();
ILabelProvider[] labels = new ILabelProvider[columnCount];
extractLabelProvider(labels);
// write header
String label = viewer.getTree().getColumn(0).getText();
for (int ii = 0; ii < depth; ii++) // $NON-NLS-1$
printer.print(label + " " + (ii + 1));
for (int ii = 1; ii < columnCount; ii++) printer.print(viewer.getTree().getColumn(ii).getText());
printer.println();
// write body
LinkedList<String> path = new LinkedList<>();
for (Object element : provider.getElements(null)) {
writeLine(printer, provider, labels, depth, path, element);
}
}
}
use of org.apache.commons.csv.CSVPrinter in project portfolio by buchen.
the class AktienfreundeNetExporter method exportAllTransactions.
/**
* Export all transactions in 'aktienfreunde.net' Format
*/
public void exportAllTransactions(File file, Client client) throws IOException {
// collect transactions
List<? extends Transaction> transactions = Stream.concat(client.getAccounts().stream(), client.getPortfolios().stream()).flatMap(//
l -> l.getTransactions().stream()).sorted(//
new Transaction.ByDate()).collect(Collectors.toList());
// write to file
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
CSVPrinter printer = new CSVPrinter(writer);
printer.setStrategy(CSVExporter.STRATEGY);
writeHeader(printer);
// only buy/sell/dividend transactions
for (Transaction t : transactions) {
if (t instanceof AccountTransaction)
writeDividend(printer, (AccountTransaction) t);
else if (t instanceof PortfolioTransaction)
writeBuySell(printer, (PortfolioTransaction) t);
}
}
}
use of org.apache.commons.csv.CSVPrinter in project portfolio by buchen.
the class CSVExporter method exportPortfolioTransactions.
public void exportPortfolioTransactions(File file, Portfolio portfolio) throws IOException {
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
CSVPrinter printer = new CSVPrinter(writer);
printer.setStrategy(STRATEGY);
printer.println(new String[] { //
Messages.CSVColumn_Date, //
Messages.CSVColumn_Type, //
Messages.CSVColumn_Value, //
Messages.CSVColumn_TransactionCurrency, //
Messages.CSVColumn_GrossAmount, //
Messages.CSVColumn_CurrencyGrossAmount, //
Messages.CSVColumn_ExchangeRate, //
Messages.CSVColumn_Fees, //
Messages.CSVColumn_Taxes, //
Messages.CSVColumn_Shares, //
Messages.CSVColumn_ISIN, //
Messages.CSVColumn_WKN, //
Messages.CSVColumn_TickerSymbol, //
Messages.CSVColumn_SecurityName, Messages.CSVColumn_Note });
for (PortfolioTransaction t : portfolio.getTransactions()) {
printer.print(t.getDateTime().toString());
printer.print(t.getType().toString());
printer.print(Values.Amount.format(t.getType().isLiquidation() ? -t.getAmount() : t.getAmount()));
printer.print(t.getCurrencyCode());
// gross amount
Optional<Unit> grossAmount = t.getUnit(Unit.Type.GROSS_VALUE);
if (grossAmount.isPresent()) {
Money forex = grossAmount.get().getForex();
printer.print(Values.Amount.format(forex.getAmount()));
printer.print(forex.getCurrencyCode());
printer.print(Values.ExchangeRate.format(grossAmount.get().getExchangeRate()));
} else {
// $NON-NLS-1$
printer.print("");
// $NON-NLS-1$
printer.print("");
// $NON-NLS-1$
printer.print("");
}
printer.print(Values.Amount.format(t.getUnitSum(Unit.Type.FEE).getAmount()));
printer.print(Values.Amount.format(t.getUnitSum(Unit.Type.TAX).getAmount()));
printer.print(Values.Share.format(t.getShares()));
printSecurityInfo(printer, t);
printer.print(escapeNull(t.getNote()));
printer.println();
}
}
}
use of org.apache.commons.csv.CSVPrinter in project portfolio by buchen.
the class CSVExporter method exportSecurityPrices.
public void exportSecurityPrices(File file, Security security) throws IOException {
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
CSVPrinter printer = new CSVPrinter(writer);
printer.setStrategy(STRATEGY);
printer.println(new String[] { Messages.CSVColumn_Date, Messages.CSVColumn_Quote });
for (SecurityPrice p : security.getPrices()) {
printer.print(p.getDate().toString());
printer.print(Values.Quote.format(p.getValue()));
printer.println();
}
}
}
Aggregations