I have a list of Services, for sample:
public class Service {
private long id;
private String name;
private BigDecimal value;
}
List<Service> services;
my user can add a lot of services, but I need to show a grouped services, If my user add 3 times the service with id
1, I need to show only one time but with a properties quantity
* EDIT *
I have this class:
public class ServicoCalculado implements Serializable{
private Long idServico;
private String nmServico;
private BigDecimal vlBase = BigDecimal.ZERO;
private BigDecimal vlTotal = BigDecimal.ZERO;
// getters e setters
}
so my User can add a lot of services:
List< ServicoCalculado> services = new ArrayList<>();
services.add(new ServicoCalculado(1, 'name 1', 1,2);
services.add(new ServicoCalculado(1, 'name 1', 1,2);
services.add(new ServicoCalculado(1, 'name 1', 1,2);
services.add(new ServicoCalculado(2, 'name 2', 2,3);
services.add(new ServicoCalculado(3, 'name 3', 2,4);
So then I have a class to show in a grid:
public class ServicosVO {
private Long idServico;
private String nmServico;
private BigDecimal vlBase;
private BigDecimal total;
private int qtd;
}
So I need to transform the first List in a List of second
This is the output
idServico || nmServico || vlBase || total || qtd
1 || name 1 || 3 || 6 || 3
2 || name 2 || 2 || 3 || 1
3 || name 3 || 2 || 4 || 1