Let's get a simple example:
Class Foo{
private BigDecimal item1;
private BigDecimal item2;
private BigDecimal item3;
private BigDecimal item4;
private BigDecimal item5;
//setters and getters
public BigDecimal getTotal(){
BigDecimal total = BigDecimal.ZERO;
if(null != item1){
total =total .add(item1);
}
if(null != item2){
total =total .add(item2);
}
...
...
}
}
I am summing in entity level. this is correct way or not?
can any one give me better code for getting total Value