I have 2 List of the same type say
class Orders {
Strig User;
String tradeDate;
BigDecimal Qty;
}
and after comparison, I want to convert to list of another object say
class DiffOrders {
String User;
String tradeDate;
BigDecimal currentQty;
BigDecimal prevQty;
}
I have two lists of Orders
List<Orders>currentOrders;
List<Orders>prevOrders;
List<Orders> DiffOrders = current.stream()
.filter(curr->previous.stream().anyMatch(prev->OrderPredicate.orderDiffSize(curr, prev)))
.collect(Collectors.toList());
For orders on the same date and for the same user I want to capture the quantity in the matching order.
I am able to find the List<Orders> that matched. But not sure how to capture and convert to the List<DiffOrders> of new Class. Could you please help?
edit 1: OrderPredicate.orderDiffSize is a simple function that compares the user, trade date, quantity, and sign (+ for sell, - for buy) for the current and previous order. Not provided here for brevity.
edit 2: The size of the prev/current list is reasonable and can ignore o log n computation issues.
edit 3: Removed direction to keep it simple. For eg, I have orders in prevOrders and CurrentOrders on 01-Jul, 02-Jul, 03-Jul respectively. If the order quantity is different for the same date I want to put it in DiffOrders with quantity from current and previous. Hope this makes it clear.
MatchOrdersclass? Can you add a sample input and output to explain this?Stream<Order>and finish withStream<MatchedOrder>, mapping is your friend, i.e.:mapfunction, which requires you to specify how would you like to convertOrdertoMatchedOrder. Simple Input and Output would help immensely.