MCPcopy Create free account
hub / github.com/Card-Forge/forge / CardUtil

Class CardUtil

forge-gui-mobile/src/forge/adventure/util/CardUtil.java:44–980  ·  view source on GitHub ↗

Utility class to deck generation and card filtering

Source from the content-addressed store, hash-verified

42 * Utility class to deck generation and card filtering
43 */
44public 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);

Callers

nothing calls this directly

Calls 5

getFormatsMethod · 0.95
getPioneerMethod · 0.80
getModernMethod · 0.80
getVintageMethod · 0.80
getStandardMethod · 0.80

Tested by

no test coverage detected