i have list of trades, each trades has some attributes like source now, from the list of trades, i want to get all trades that have same source value and combine them together into one trade, for example
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
now based on source information, i should combine trades, so my updated list of trade would be
tradeName quote source quantity price
Google GOOG Goldman Sachs 100 610
Microsoft MSFT Barclays 1400 28
I am not sure about comparison part, how to go about solving it?
Tried following approach,
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.
}
Tradeobject that you defined, butString[] tradein your loop suggests otherwise