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; + } }