I am trying to optimize this code. The only optimization I can think of is to ?¿? a return
or break
statement after applyOfferChanges(…)
inside the second if
condition which does not work either because there could be multiple matches. I cannot either use a map for favoriteMerchantsList
because getFavoriteMerchantsList()
return type is a list (of favorited merchants). Any ideas?
void applyFavoriteChangesToMerchantStore(){
List<Merchant> favoriteMerchantsList = FavoriteMerchantStore.getInstance().getFavoriteMerchantsList();
if(favoriteMerchantsList != null && !favoriteMerchantsList.isEmpty()) {
List<Merchant> storeMerchantList = MerchantStore.getInstance().getMerchantList();
for (Merchant storeMerchant : storeMerchantList) {
for (Merchant favoriteMerchant: favoriteMerchantsList){
if(TextUtils.equals(storeMerchant.getId(), favoriteMerchant.getId())){
//merchant match found
//set merchant favorite status
storeMerchant.setFavoriteMerchant(favoriteMerchant.getFavoriteMerchant());
//set offer favorite status
applyOfferChanges(favoriteMerchant.getOffferList(),
storeMerchant.getOffferList());
}
}
}
}
}