Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b2576dc

Browse files
committedFeb 27, 2024·
refactored the null empty condition amd list iteration with foreach
1 parent 1c9b022 commit b2576dc

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed
 

‎core/data/src/main/java/org/mifos/mobilewallet/core/data/fineract/entity/mapper/AccountMapper.kt

+9-14
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,16 @@ class AccountMapper @Inject constructor(private val currencyMapper: CurrencyMapp
1010
fun transform(clientAccounts: ClientAccounts?): List<Account> {
1111
val accountList = mutableListOf<Account>()
1212

13-
if (clientAccounts != null
14-
&& !clientAccounts.savingsAccounts.isNullOrEmpty()) {
15-
16-
for (savingAccount in clientAccounts.savingsAccounts) {
17-
val account = Account().apply {
18-
name = savingAccount.productName
19-
number = savingAccount.accountNo
20-
id = savingAccount.id
21-
balance = savingAccount.accountBalance
22-
currency = currencyMapper.transform(savingAccount.currency)
23-
productId = savingAccount.productId.toLong()
24-
}
25-
26-
accountList.add(account)
13+
clientAccounts?.savingsAccounts?.forEach { savingAccount ->
14+
val account = Account().apply {
15+
name = savingAccount.productName
16+
number = savingAccount.accountNo
17+
id = savingAccount.id
18+
balance = savingAccount.accountBalance
19+
currency = currencyMapper.transform(savingAccount.currency)
20+
productId = savingAccount.productId.toLong()
2721
}
22+
accountList.add(account)
2823
}
2924
return accountList
3025
}

‎core/data/src/main/java/org/mifos/mobilewallet/core/data/fineract/entity/mapper/CurrencyMapper.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package org.mifos.mobilewallet.core.data.fineract.entity.mapper
22

33
import com.mifos.mobilewallet.model.entity.accounts.savings.Currency
44
import javax.inject.Inject
5+
import com.mifos.mobilewallet.model.domain.Currency as DomainCurrency
56

67
/**
78
* Created by naman on 17/8/17.
89
*/
910
class CurrencyMapper @Inject internal constructor() {
10-
fun transform(savingsCurrency: Currency): com.mifos.mobilewallet.model.domain.Currency {
11-
val currency: com.mifos.mobilewallet.model.domain.Currency =
12-
com.mifos.mobilewallet.model.domain.Currency()
11+
fun transform(savingsCurrency: Currency): DomainCurrency {
12+
val currency: DomainCurrency =
13+
DomainCurrency()
1314
currency.code = savingsCurrency.code
1415
currency.displayLabel = savingsCurrency.displayLabel
1516
currency.displaySymbol = savingsCurrency.displaySymbol

‎core/data/src/main/java/org/mifos/mobilewallet/core/data/fineract/entity/mapper/TransactionMapper.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ class TransactionMapper @Inject constructor(private val currencyMapper: Currency
1212
fun transformTransactionList(savingsWithAssociations: SavingsWithAssociations?): List<Transaction> {
1313
val transactionList = ArrayList<Transaction>()
1414

15-
if (savingsWithAssociations != null && !savingsWithAssociations.transactions.isNullOrEmpty()) {
16-
for (transactions in savingsWithAssociations.transactions) {
17-
transactionList.add(transformInvoice(transactions))
18-
}
15+
savingsWithAssociations?.transactions?.forEach { transaction ->
16+
transactionList.add(transformInvoice(transaction))
1917
}
2018
return transactionList
2119
}

‎core/data/src/main/java/org/mifos/mobilewallet/core/domain/usecase/account/TransferFunds.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class TransferFunds @Inject constructor( private val apiRepository: FineractRepo
111111

112112
override fun onNext(clientAccounts: ClientAccounts) {
113113
val accounts = clientAccounts.savingsAccounts
114-
if (accounts != null && accounts.isNotEmpty()) {
114+
if (!accounts.isNullOrEmpty()) {
115115
var walletAccount: SavingAccount? = null
116116
for (account in accounts) {
117117
if (account.productId == Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) {

0 commit comments

Comments
 (0)
Please sign in to comment.