我有交易列表,每个交易现在都有一些属性,例如来源,从交易列表中,我想获得所有具有相同来源价值的交易并将它们组合成一个交易,例如
tradeName quote source quantity price
Google GOOG Goldman Sachs 15 610
Microsoft MSFT Barclays 400 28
Google GOOG Goldman Sachs 45 610
Google GOOG Goldman Sachs 40 610
Microsoft MSFT Barclays 1000 28
现在基于源信息,我应该合并交易,所以我更新的交易清单将是
tradeName quote source quantity price
Google GOOG Goldman Sachs 100 610
Microsoft MSFT Barclays 1400 28
我不确定比较部分,如何解决?
尝试了以下方法,
for (Trade trade : tradeList)
{
//Not sure how to compare this.trade.source with all sources
//of all trades present in the trade.
//Logic should be if source matches then quantity should be added
//but am not sure how comparison would work.
}
Class Trade
{
private tradeName;
private quote;
private source;
private quantity;
private price;
//Getters and Setters for each of above mentioned attributes.
}