Last active
September 8, 2021 02:02
-
-
Save wkdalsgh192/5b1c7d51e02712f456a4cac99e9fe74b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PayGroups { | |
private List<Pay> pays; | |
public PayGroups(List<Pay> pays) { | |
this.pays = pays; | |
} | |
public Long getPayPalSum() return getTotalSum(pay -> PayType.isPayPal(pay.getPayType())); | |
public Long getVisaSum() return getTatalSum(pay -> PayType.isVisa(pay.getPayType())); | |
public Long getTotalSum(Predicate<Pay> predicate) { | |
return pays.stream() | |
.filter(predicate) | |
.mapToLong(Pay::getAmount) | |
.sum(); | |
} | |
} | |
public void managingStateAndAction() { | |
List<Pay> pays = Arrays.asList( | |
new Pay(PAYPAL, 1000), | |
new Pay(VISA, 2000), | |
new Pay(MASTER_CARD, 3000), | |
new Pay(UNION_CARD, 5000) | |
); | |
PayGroups payGroups = new PayGroups(pays); | |
Long visaExpenditure = payGroups.getVisaSum(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment