I have 3 queues of records (of idential size and datetime order) and want to combine them record by record.
It is similar to below:
record BuyOrder(String date, String product, double buyPx) {};
record SellOrder(String date, double sellPx) {};
record Transaction(String date, double commission, int volume) {};
Queue<BuyOrder> buys = new LinkedList<>();
Queue<SellOrder> sells = new Linkedlist<>();
Queue<Transaction> transactions = new LinkedList<>();
Queue<Object[]> combined = new LinkedList<>();
The combined
queue should be [date, product, buyPx, sellPx, commission, volume], [date, product, buyPx, sellPx, commission, volume], ...
. How can I do this?
I am using a loop but believe that there gotta be a more efficient and simpler way. Such as using stream()
?
for (BuyOrder buy: buys) {
SellOrder sell = sells.poll(); //remove the head
Transaction transaction = transactions.poll();
combined.add(new Object[]{buy.date(), buy.product(), buy.buyPx(), sell.sellPx(), transaction.commission(), transaction.volume()});
}