private PortfolioTransaction convertTo(PortfolioTransaction t, PortfolioTransaction.Type type) { PortfolioTransaction clone = new PortfolioTransaction(); clone.setType(type); clone.setDate(t.getDate()); clone.setCurrencyCode(t.getCurrencyCode()); clone.setSecurity(t.getSecurity()); clone.setAmount(t.getAmount()); clone.setShares(t.getShares()); clone.addUnits(t.getUnits()); return clone; }
private static void collectDatesAndValues( Date start, Date end, ClientSnapshot snapshotStart, ClientSnapshot snapshotEnd, List<Transaction> transactions, List<Date> dates, List<Double> values) { Calendar cal = Calendar.getInstance(); cal.setTime(start); dates.add(cal.getTime()); values.add(-(snapshotStart.getAssets()) / Values.Amount.divider()); for (Transaction t : transactions) { cal.setTime(t.getDate()); dates.add(cal.getTime()); if (t instanceof AccountTransaction) { AccountTransaction at = (AccountTransaction) t; long amount = at.getAmount(); if (at.getType() == Type.DEPOSIT || at.getType() == Type.TRANSFER_IN) amount = -amount; values.add(amount / Values.Amount.divider()); } else if (t instanceof PortfolioTransaction) { PortfolioTransaction pt = (PortfolioTransaction) t; long amount = pt.getAmount(); if (pt.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND || pt.getType() == PortfolioTransaction.Type.TRANSFER_IN) amount = -amount; values.add(amount / Values.Amount.divider()); } else { throw new UnsupportedOperationException(); } } cal.setTime(end); dates.add(cal.getTime()); values.add(snapshotEnd.getAssets() / Values.Amount.divider()); }