hope someone can help me. I have a POJO with the following structure:
public class Invoice{
private String docNum;
private String customer;
private ArrayList<InvoiceDetails> invoiceDetails;
}
And another POJO with the following
public class InvoiceDetails{
private String vatGroup;
private Double vatAmount;
private Double amount;
}
In addition, I have a third with the following
public class VatType{
private String vatGroup;
private Double vatAmount;
private Double amount;
}
What I'm trying to do is reduce Listfrom Invoiceto Listfrom from VatTypegrouped by vatGroup. Like de DISTINCTc SQL. Let's say I have the following list:
InvoiceDetails idA1 = new InvoiceDetails("S1", 100.0, 40.0);
InvoiceDetails idA2 = new InvoiceDetails("S2", 140.0, 40.0);
InvoiceDetails idA3 = new InvoiceDetails("A1", 50.0, 10.0);
ArrayList<InvoiceDetails> listA = new ArrayList<>();
listA.add(idA1);
listA.add(idA2);
listA.add(idA3);
Invoice invoiceA = new Invoice();
invoiceA.setDetailList(listA);
InvoiceDetails idB1 = new InvoiceDetails("S1", 200.0, 50.0);
InvoiceDetails idB2 = new InvoiceDetails("S2", 240.0, 50.0);
InvoiceDetails idB2 = new InvoiceDetails("A1", 100.0, 20.0);
ArrayList<InvoiceDetails> listB = new ArrayList<>();
listB.add(idB1);
listB.add(idB2);
listB.add(idB3);
Invoice invoiceB = new Invoice();
invoiceB.setDetailList(listB);
List<Invoice> invoiceList = new ArrayList<>();
invoiceList.add(invoiceA);
invoiceList.add(invoiceB);
The expected result will be Listof VatTypewith the following points:
("S1",300.0,90.0)
("S2",380.0,90.0)
("A1",150.0,30.0)
How can I get this list using streamone shot. Avoid iterating through Lists? thanks in advance