Class Order{
List<Transaction> transactions
}
Class Transaction{
public String state;
public Long id;
public Long dateInMillis;
}
I'm looking for an efficient way to do the following
I have a list of orders and each order can have multiple transactions each.Transaction can be in two states i.e. ACTIVE, COMPLETED (and a bunch of states in between we don't care about). For each order, we create a transaction(ACTIVE) when we start the process and create another transaction(COMPLETED) when we end it. I want to generate list of transactions with their requestDate & completionDate. For a transaction in ACTIVE status, requestDate and Completion date is the transaction date itself. For a transaction in COMPLETED state, requestDate is the date of corresponding ACTIVE transaction and completion date is the date of current transaction i.e. COMPLETED state one.
For e.g. two transactions t1 & t2 where t1 has state ACTIVE and t2 has state COMPLETED.
orders.stream()
.forEach(order -> {
order.getTransactions().stream().forEach(transaction -> {
});
ResultObject obj = new ResultObject();
obj.setTransactionId(transaction.getId());
if(transaction.getState()=="ACTIVE"){
obj.setRequestDateInMillis(transaction.getDateInMillis);
obj.setCompletionDateInMillis(transaction.getDateInMillis());
}else if(transaction.getState()=="COMPLETED"){
obj.setCompletionDateInMillis(transaction.getDateInMillis());
TODO: find transaction for this order which is in ACTIVE state and set that time as RequestDate for current transaction
}
});