@@ -120,47 +120,14 @@ public LocalDate getNextDistributionDateForCode(String code) {
120120 .collect (Collectors .toCollection (PriorityQueue ::new )));
121121 }
122122
123- public BigDecimal getTotalFrankedDividendsForCode (String code ) {
124- return this .sumAmountForAccountWithCode (FRANKED_DIVIDEND , code );
125- }
126-
127- public BigDecimal getTotalUnFrankedDividendsForCode (String code ) {
128- return this .sumAmountForAccountWithCode (UNFRANKED_DIVIDEND , code );
129- }
130-
131- public BigDecimal getTotalMiscIncomeForCode (String code ) {
132- return this .sumAmountForAccountWithCode (INCOME_OTHER , code );
133- }
134-
135- public BigDecimal getTotalCapitalGainsForCode (String code ) {
136- return this .sumAmountForAccountWithCode (CAPITAL_GAINS_INCOME , code );
137- }
138-
139- // None in conversion
140- public BigDecimal getTotalCapitalLossesForCode (String code ) {
141- return this .sumAmountForAccountWithCode (CAPITAL_LOSSES_INCOME , code );
142- }
143-
144- public BigDecimal getTotalCapitalReturnsForCode (String code ) {
145- return this .sumAmountForAccountWithCode (CAPITAL_RETURN_INCOME , code );
146- }
147-
148- // Fund type distribution or reinvestment
149- public BigDecimal getTotalDistributionsForCode (String code ) {
150- return this .sumAmountForAccountWithCode (DISTRIBUTION_INCOME , code )
151- .add (this .sumAmountForAccountWithCode (REINVESTMENT_INCOME , code ));
152- }
153-
154123 public BigDecimal getTotalInvestmentIncomeForCode (String code ) {
155- return this .getTotalFrankedDividendsForCode (code )
156- .add (this .getTotalUnFrankedDividendsForCode (code ))
157- .add (this .getTotalMiscIncomeForCode (code ))
158- .add (this .getTotalCapitalGainsForCode (code ))
159- .add (this .getTotalCapitalReturnsForCode (code ))
160- .add (this .getTotalDistributionsForCode (code ));
124+ return Arrays .stream (INVESTMENT_INCOME
125+ .split ("," ))
126+ .map (x -> this .sumAmountForAccountsWithCode (x , code ))
127+ .reduce (BigDecimal .ZERO , BigDecimal ::add );
161128 }
162129
163- private BigDecimal sumAmountForAccountWithCode (String accountType , String code ) {
130+ private BigDecimal sumAmountForAccountExactWithCode (String accountType , String code ) {
164131 return accounts .stream ()
165132 .filter (account -> account .getName ().equalsIgnoreCase (accountType ))
166133 .map (account -> account .getMovementsForCode (code ))
@@ -170,6 +137,16 @@ private BigDecimal sumAmountForAccountWithCode(String accountType, String code)
170137 .setScale (2 , RoundingMode .HALF_UP );
171138 }
172139
140+ private BigDecimal sumAmountForAccountsWithCode (String accountType , String code ) {
141+ return accounts .stream ()
142+ .filter (account -> account .getName ().toLowerCase ().startsWith (accountType .toLowerCase ()))
143+ .map (account -> account .getMovementsForCode (code ))
144+ .map (this ::sum )
145+ .reduce (BigDecimal .ZERO , BigDecimal ::add )
146+ .abs ()
147+ .setScale (2 , RoundingMode .HALF_UP );
148+ }
149+
173150 private BigDecimal sum (Collection <Movement > movements ) {
174151 return movements .stream ()
175152 .map (Movement ::amount )
0 commit comments