Skip to content

Commit

Permalink
Refactor 2 predicates as single predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
ghubstan committed Aug 16, 2021
1 parent 6a4aced commit d709338
Showing 1 changed file with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ public void fillOfferBookListItems() {
// Investigate why....
offerBookListItems.clear();
offerBookListItems.addAll(offerBookService.getOffers().stream()
.filter(o -> !isOfferIdBanned(o))
.filter(o -> isV3NodeAddressCompliant(o))
.filter(o -> isOfferAllowed(o))
.map(OfferBookListItem::new)
.collect(Collectors.toList()));

Expand Down Expand Up @@ -288,21 +287,16 @@ private Optional<OfferBookListItem> getOfferBookListItem(Offer offer) {
.findFirst();
}

private boolean isOfferIdBanned(Offer offer) {
return filterManager.isOfferIdBanned(offer.getId());
}

private boolean isV3NodeAddressCompliant(Offer offer) {
return !OfferRestrictions.requiresNodeAddressUpdate()
private boolean isOfferAllowed(Offer offer) {
boolean isBanned = filterManager.isOfferIdBanned(offer.getId());
boolean isV3NodeAddressCompliant = !OfferRestrictions.requiresNodeAddressUpdate()
|| Utils.isV3Address(offer.getMakerNodeAddress().getHostName());
return !isBanned && isV3NodeAddressCompliant;
}

private boolean isStoredLocally(Offer offer) {
return offerBookService.getOffers().stream()
.anyMatch(o -> o.getId().equals(offer.getId())
&& !isOfferIdBanned(o)
&& isV3NodeAddressCompliant(o)
);
.anyMatch(o -> o.getId().equals(offer.getId()) && isOfferAllowed(o));
}

private void fillOfferCountMaps() {
Expand Down

0 comments on commit d709338

Please sign in to comment.