Utility class to deck generation and card filtering
| 42 | * Utility class to deck generation and card filtering |
| 43 | */ |
| 44 | public class CardUtil { |
| 45 | public static final class CardPredicate implements Predicate<PaperCard> { |
| 46 | enum ColorType { |
| 47 | Any, |
| 48 | Colorless, |
| 49 | MultiColor, |
| 50 | MonoColor |
| 51 | } |
| 52 | |
| 53 | private final List<CardRarity> rarities = new ArrayList<>(); |
| 54 | private final List<String> editions = new ArrayList<>(); |
| 55 | private final List<String> subType = new ArrayList<>(); |
| 56 | private final List<String> keyWords = new ArrayList<>(); |
| 57 | private final List<CardType.CoreType> type = new ArrayList<>(); |
| 58 | private final List<CardType.Supertype> superType = new ArrayList<>(); |
| 59 | private final List<Integer> manaCosts = new ArrayList<>(); |
| 60 | private final Pattern text; |
| 61 | private final boolean matchAllSubTypes; |
| 62 | private final boolean matchAllColors; |
| 63 | private int colors; |
| 64 | private final ColorType colorType; |
| 65 | private final boolean shouldBeEqual; |
| 66 | private final List<String> deckNeeds = new ArrayList<>(); |
| 67 | private final String minDate; |
| 68 | private final static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
| 69 | |
| 70 | private static Date parseDate(String date) { |
| 71 | if (date.length() <= 7) |
| 72 | date = date + "-01"; |
| 73 | try { |
| 74 | return formatter.parse(date); |
| 75 | } catch (Exception e) { |
| 76 | return new Date(); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public boolean test(final PaperCard card) { |
| 82 | if (!this.rarities.isEmpty() && !this.rarities.contains(card.getRarity())) |
| 83 | return !this.shouldBeEqual; |
| 84 | if (!this.editions.isEmpty() && !this.editions.contains(card.getEdition())) { |
| 85 | boolean found = false; |
| 86 | List<PaperCard> allPrintings = FModel.getMagicDb().getCommonCards().getAllCards(card); |
| 87 | for (PaperCard c : allPrintings) { |
| 88 | if (this.editions.contains(c.getEdition())) { |
| 89 | found = true; |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | if (!found) |
| 94 | return !this.shouldBeEqual; |
| 95 | } |
| 96 | if (!this.minDate.isEmpty()) { |
| 97 | boolean found = false; |
| 98 | List<PaperCard> allPrintings = FModel.getMagicDb().getCommonCards().getAllCards(card); |
| 99 | List<CardEdition> cardEditionList = new ArrayList<>(); |
| 100 | |
| 101 | Date d = parseDate(this.minDate); |
nothing calls this directly
no test coverage detected