Sum Fields based on Certain Field

Hi, i have table Orders with three fields Bigdecimal : OneShotPayment , RecurrentPayment , totalamout

I’ve a table OrderDetails, with Field indicates Type with “R” or “U” for each R = Recurrent, U = OneShot , and a field Amount.

In Screen Orders.Edit i have this code, and work for totalamount:

        BigDecimal importe3 = BigDecimal.ZERO;
        for (ContratosProductos linea : productostabla.getItems()) {
            importe3 = importe3.add(linea.getAmount());

How can i Select on getAmount, only Type “R” or Type “U” ?

In the iteration?

if (linea.getType().equals("R")) {
    importe3 = importe3.add(linea.getAmount());