double (double amount, Player player, List<CashOutDebitInfo> freeDebits, UserCashOut userCashOut, Session ses) { double checkAmount = amount; int i = 0; for (CashOutDebitInfo debitInfo : freeDebits) { Transaction credit = new Transaction(); if (checkAmount > debitInfo.remainder) { credit.setAmount(-debitInfo.remainder); checkAmount -= debitInfo.remainder; } else { credit.setAmount(-checkAmount); checkAmount = 0; } credit.setCreateDate(new Date()); credit.setOriginalDebitTransaction(debitInfo.debit); debitInfo.debit.getCreditTransactions().add(credit); credit.setPlayer(player); credit.setType(TransactionType.CASHOUT); credit.setStatus(TransactionStatus.PENDING); credit.setUserCashOut(userCashOut); userCashOut.getCredits().add(credit); debitInfo.credit = credit; ses.save(credit); i++; if (checkAmount <= 0) { break; } } int size = freeDebits.size(); for (int j = i; j < size; j++) { freeDebits.remove(i); } return checkAmount; }