Skip to content

Commit 06c843b

Browse files
authored
Fixes based on static analysis (#765)
1 parent 480ca90 commit 06c843b

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

customer/src/main/java/com/yas/customer/service/UserAddressService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.ArrayList;
1919
import java.util.Comparator;
2020
import java.util.List;
21+
import java.util.Objects;
2122
import java.util.stream.Collectors;
2223

2324
@Service
@@ -107,7 +108,7 @@ public void chooseDefaultAddress(Long id) {
107108
List<UserAddress> userAddressList = userAddressRepository.findAllByUserId(userId);
108109
List<UserAddress> newUserAddressList = new ArrayList<>();
109110
for (UserAddress userAddress : userAddressList) {
110-
if (userAddress.getAddressId() == id) {
111+
if (Objects.equals(userAddress.getAddressId(), id)) {
111112
userAddress.setIsActive(true);
112113
} else {
113114
userAddress.setIsActive(false);

product/src/main/java/com/yas/product/service/ProductService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -841,10 +841,9 @@ public void updateProductQuantity(List<ProductQuantityPostVm> productQuantityPos
841841
List<Long> productIds = productQuantityPostVms.stream().map(ProductQuantityPostVm::productId).toList();
842842
List<Product> products = productRepository.findAllByIdIn(productIds);
843843
products.parallelStream().forEach(product -> {
844-
ProductQuantityPostVm productQuantityPostVm = productQuantityPostVms.parallelStream()
845-
.filter(productPostVm -> product.getId().equals(productPostVm.productId())).findFirst().get();
846-
847-
product.setStockQuantity(productQuantityPostVm.stockQuantity());
844+
Optional<ProductQuantityPostVm> productQuantityPostVmOptional = productQuantityPostVms.parallelStream()
845+
.filter(productPostVm -> product.getId().equals(productPostVm.productId())).findFirst();
846+
productQuantityPostVmOptional.ifPresent(productQuantityPostVm -> product.setStockQuantity(productQuantityPostVm.stockQuantity()));
848847
});
849848

850849
productRepository.saveAll(products);

tax/src/main/java/com/yas/tax/service/TaxRateService.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.yas.tax.service;
22

3-
import com.yas.tax.exception.DuplicatedException;
43
import com.yas.tax.exception.NotFoundException;
54
import com.yas.tax.model.TaxRate;
65
import com.yas.tax.repository.TaxClassRepository;
@@ -135,20 +134,16 @@ public TaxRateListGetVm getPageableTaxRates(int pageNo, int pageSize) {
135134
//Call location service to get country names and state or province name by list of state or province ids
136135
List<StateOrProvinceAndCountryGetNameVm> stateOrProvinceAndCountryGetNameVms = locationService.getStateOrProvinceAndCountryNames(stateOrProvinceIds);
137136
taxRates.forEach(taxRate -> {
138-
StateOrProvinceAndCountryGetNameVm stateOrProvinceAndCountryGetNameVm = stateOrProvinceAndCountryGetNameVms.stream()
139-
.filter(x -> x.stateOrProvinceId().equals(taxRate.getStateOrProvinceId()))
140-
.findAny()
141-
.orElse(null);
142-
143-
if(stateOrProvinceAndCountryGetNameVm != null) {
144-
taxRateGetDetailVms.add(new TaxRateGetDetailVm(
145-
taxRate.getId(),
146-
taxRate.getRate(),
147-
taxRate.getZipCode(),
148-
taxRate.getTaxClass().getName(),
149-
stateOrProvinceAndCountryGetNameVm.stateOrProvinceName(),
150-
stateOrProvinceAndCountryGetNameVm.countryName()));
151-
}
137+
stateOrProvinceAndCountryGetNameVms.stream()
138+
.filter(x -> x.stateOrProvinceId().equals(taxRate.getStateOrProvinceId()))
139+
.findAny().ifPresent(stateOrProvinceAndCountryGetNameVm -> taxRateGetDetailVms.add(new TaxRateGetDetailVm(
140+
taxRate.getId(),
141+
taxRate.getRate(),
142+
taxRate.getZipCode(),
143+
taxRate.getTaxClass().getName(),
144+
stateOrProvinceAndCountryGetNameVm.stateOrProvinceName(),
145+
stateOrProvinceAndCountryGetNameVm.countryName())));
146+
152147
});
153148
}
154149

0 commit comments

Comments
 (0)