Use a stream filter instead of a if clause
This commit is contained in:
chimp1984 2020-09-06 20:16:00 -05:00
parent cafbbdf94c
commit 00fe80ef0e
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3

View File

@ -200,18 +200,19 @@ public class MultipleHolderNameDetection {
private Map<String, List<Dispute>> getAllDisputesByTraderMap() {
Map<String, List<Dispute>> allDisputesByTraderMap = new HashMap<>();
disputeManager.getDisputesAsObservableList()
.forEach(dispute -> {
disputeManager.getDisputesAsObservableList().stream()
.filter(dispute -> {
Contract contract = dispute.getContract();
PaymentAccountPayload paymentAccountPayload = isBuyer(dispute) ?
contract.getBuyerPaymentAccountPayload() :
contract.getSellerPaymentAccountPayload();
if (paymentAccountPayload instanceof PayloadWithHolderName) {
String traderPubKeyHash = getSigPubKeyHashAsHex(dispute);
allDisputesByTraderMap.putIfAbsent(traderPubKeyHash, new ArrayList<>());
List<Dispute> disputes = allDisputesByTraderMap.get(traderPubKeyHash);
disputes.add(dispute);
}
return paymentAccountPayload instanceof PayloadWithHolderName;
})
.forEach(dispute -> {
String traderPubKeyHash = getSigPubKeyHashAsHex(dispute);
allDisputesByTraderMap.putIfAbsent(traderPubKeyHash, new ArrayList<>());
List<Dispute> disputes = allDisputesByTraderMap.get(traderPubKeyHash);
disputes.add(dispute);
});
return allDisputesByTraderMap;
}