我有一个Payment对象,其中包含日期和金额字段。
List<Payment>
我需要遍历“付款”,然后将日期和金额放入地图中(日期是关键)。 可以说我在“付款”对象中有一些日期和金额字段的数据,如下所示。
date: 14-01-2018, amount: 10
date: 16-01-2018, amount: 30
date: 11-01-2018, amount: 50
date: 19-01-2012, amount: 30
date: 12-01-2017, amount: 70
现在,我将按顺序获取此数据,并希望按如下所示的排序顺序(按日期)将这些数据放入地图中:
1st entry in map:
date: 14-01-2018, amount: 10
2nd entry:
date: 14-01-2018, amount: 10
date: 16-01-2018, amount: 40(here adding earlier date amount which is 10 for 14-01-2018 )
3rd entry:
date: 11-01-2018, amount: 50
date: 14-01-2018, amount: 60 (in 2nd entry for this date amount was 10, but since date 11-01-2018 having amount 50 then i adding 50 to 10)
date: 16-01-2018, amount: 90(same here, as in 2nd entry for this date amount was 40 but need to add 50 of 11-01-2018 as this date is before)
4th entry:
date: 19-01-2012, amount: 30 (since this date will come first i need to add this amount to all later date's amount)
date: 11-01-2018, amount: 80
date: 14-01-2018, amount: 90
date: 16-01-2018, amount: 120
5th entry:
date: 19-01-2012, amount: 30
date: 12-01-2017, amount: 70(this date will come at 2nd place because of sorting, its amount is 70 but it's earlier date 9-01-2012 has amount 30, so need to add that amount and 12-01-2017 amount will become 100, and later date's amount will increase by 70)
date: 11-01-2018, amount: 150
date: 14-01-2018, amount: 160
date: 16-01-2018, amount: 190
答案 0 :(得分:0)
您可以只使用排序的映射(例如average [0.0; 1.0; 3.0; 5.0];;
val it : Result<float,AggregateError> = Ok 2.25
)并汇总到其中:
TreeMap