From 2950a567d8405d5dda8b7de4266473cac53c873c Mon Sep 17 00:00:00 2001 From: leriomaggio Date: Sun, 22 Aug 2021 23:26:19 +0100 Subject: [PATCH] New Method to filter a card pool based on a Predicate This method will be used during the validation of each deck section. --- .../src/main/java/forge/deck/CardPool.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/forge-core/src/main/java/forge/deck/CardPool.java b/forge-core/src/main/java/forge/deck/CardPool.java index 72fe0a22d4a..a4b4145c149 100644 --- a/forge-core/src/main/java/forge/deck/CardPool.java +++ b/forge-core/src/main/java/forge/deck/CardPool.java @@ -457,4 +457,20 @@ public class CardPool extends ItemPool { } return filteredPool; } + + /** + * Applies a predicate to this CardPool's cards. + * @param predicate the Predicate to apply to this CardPool + * @return a new CardPool made from this CardPool with only the cards that agree with the provided Predicate + */ + public CardPool getFilteredPoolWithCardsCount(Predicate predicate){ + CardPool filteredPool = new CardPool(); + for(Entry entry : this.items.entrySet()){ + PaperCard pc = entry.getKey(); + int count = entry.getValue(); + if(predicate.apply(pc)) + filteredPool.add(pc, count); + } + return filteredPool; + } }