New Method to filter a card pool based on a Predicate

This method will be used during the validation of each deck section.
This commit is contained in:
leriomaggio
2021-08-22 23:26:19 +01:00
parent f541199cca
commit 2950a567d8

View File

@@ -457,4 +457,20 @@ public class CardPool extends ItemPool<PaperCard> {
}
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<PaperCard> predicate){
CardPool filteredPool = new CardPool();
for(Entry<PaperCard, Integer> entry : this.items.entrySet()){
PaperCard pc = entry.getKey();
int count = entry.getValue();
if(predicate.apply(pc))
filteredPool.add(pc, count);
}
return filteredPool;
}
}