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() { private Map<String, List<Dispute>> getAllDisputesByTraderMap() {
Map<String, List<Dispute>> allDisputesByTraderMap = new HashMap<>(); Map<String, List<Dispute>> allDisputesByTraderMap = new HashMap<>();
disputeManager.getDisputesAsObservableList() disputeManager.getDisputesAsObservableList().stream()
.forEach(dispute -> { .filter(dispute -> {
Contract contract = dispute.getContract(); Contract contract = dispute.getContract();
PaymentAccountPayload paymentAccountPayload = isBuyer(dispute) ? PaymentAccountPayload paymentAccountPayload = isBuyer(dispute) ?
contract.getBuyerPaymentAccountPayload() : contract.getBuyerPaymentAccountPayload() :
contract.getSellerPaymentAccountPayload(); contract.getSellerPaymentAccountPayload();
if (paymentAccountPayload instanceof PayloadWithHolderName) { return paymentAccountPayload instanceof PayloadWithHolderName;
String traderPubKeyHash = getSigPubKeyHashAsHex(dispute); })
allDisputesByTraderMap.putIfAbsent(traderPubKeyHash, new ArrayList<>()); .forEach(dispute -> {
List<Dispute> disputes = allDisputesByTraderMap.get(traderPubKeyHash); String traderPubKeyHash = getSigPubKeyHashAsHex(dispute);
disputes.add(dispute); allDisputesByTraderMap.putIfAbsent(traderPubKeyHash, new ArrayList<>());
} List<Dispute> disputes = allDisputesByTraderMap.get(traderPubKeyHash);
disputes.add(dispute);
}); });
return allDisputesByTraderMap; return allDisputesByTraderMap;
} }