11package forge .deck ;
22
3+ import forge .card .CardRulesPredicates ;
34import forge .card .CardType ;
45import forge .item .PaperCard ;
6+ import forge .item .PaperCardPredicates ;
57import forge .util .Localizer ;
68
7- import java .util .function .Function ;
9+ import java .util .function .Predicate ;
810
911public enum DeckSection {
1012 Main ("lblMainDeck" , Validators .DECK_AND_SIDE_VALIDATOR ),
1113 Sideboard ("lblSideboard" , Validators .DECK_AND_SIDE_VALIDATOR ),
1214 Commander ("lblCommander" , Validators .COMMANDER_VALIDATOR ),
13- Avatar ("lblAvatar" , Validators . AVATAR_VALIDATOR ),
14- Planes ("lblPlanarDeck" , Validators . PLANES_VALIDATOR ),
15- Schemes ("lblSchemeDeck" , Validators . SCHEME_VALIDATOR ),
16- Conspiracy ("lblConspiracies" , Validators . CONSPIRACY_VALIDATOR ),
17- Dungeon ("lblDungeons" , Validators . DUNGEON_VALIDATOR ),
18- Attractions ("lblAttractions" , Validators . ATTRACTION_VALIDATOR ),
19- Contraptions ("lblContraptions" , Validators . CONTRAPTION_VALIDATOR );
15+ Avatar ("lblAvatar" , PaperCardPredicates . fromRules ( CardRulesPredicates . IS_VANGUARD ) ),
16+ Planes ("lblPlanarDeck" , PaperCardPredicates . fromRules ( CardRulesPredicates . IS_PLANE_OR_PHENOMENON ) ),
17+ Schemes ("lblSchemeDeck" , PaperCardPredicates . fromRules ( CardRulesPredicates . IS_SCHEME ) ),
18+ Conspiracy ("lblConspiracies" , PaperCardPredicates . fromRules ( CardRulesPredicates . IS_CONSPIRACY ) ),
19+ Dungeon ("lblDungeons" , PaperCardPredicates . fromRules ( CardRulesPredicates . IS_DUNGEON ) ),
20+ Attractions ("lblAttractions" , PaperCardPredicates . fromRules ( CardRulesPredicates . IS_ATTRACTION ) ),
21+ Contraptions ("lblContraptions" , PaperCardPredicates . fromRules ( CardRulesPredicates . IS_CONTRAPTION ) );
2022
2123 /**
2224 * Array of DeckSections that contain nontraditional cards.
2325 */
2426 public static final DeckSection [] NONTRADITIONAL_SECTIONS = new DeckSection []{Avatar , Planes , Schemes , Conspiracy , Dungeon , Attractions , Contraptions };
2527
2628 private final String nameLbl ;
27- private final Function <PaperCard , Boolean > fnValidator ;
29+ private final Predicate <PaperCard > fnValidator ;
2830
29- DeckSection (String nameLbl , Function <PaperCard , Boolean > validator ) {
31+ DeckSection (String nameLbl , Predicate <PaperCard > validator ) {
3032 this .nameLbl = nameLbl ;
3133 fnValidator = validator ;
3234 }
@@ -49,7 +51,7 @@ public String getLocalizedShortName() {
4951
5052 public boolean validate (PaperCard card ){
5153 if (fnValidator == null ) return true ;
52- return fnValidator .apply (card );
54+ return fnValidator .test (card );
5355 }
5456
5557 // Returns the matching section for "special"/supplementary core types.
@@ -84,53 +86,18 @@ public static DeckSection smartValueOf(String value) {
8486 }
8587
8688 private static class Validators {
87- static final Function <PaperCard , Boolean > DECK_AND_SIDE_VALIDATOR = card -> {
89+ static final Predicate <PaperCard > DECK_AND_SIDE_VALIDATOR = card -> {
8890 CardType t = card .getRules ().getType ();
8991 // NOTE: Same rules applies to both Deck and Side, despite "Conspiracy cards" are allowed
9092 // in the SideBoard (see Rule 313.2)
9193 // Those will be matched later, in case (see `Deck::normalizeDeferredSections`)
9294 return !t .isConspiracy () && !t .isDungeon () && !t .isPhenomenon () && !t .isPlane () && !t .isScheme () && !t .isVanguard ();
9395 };
9496
95- static final Function <PaperCard , Boolean > COMMANDER_VALIDATOR = card -> {
97+ static final Predicate <PaperCard > COMMANDER_VALIDATOR = card -> {
9698 CardType t = card .getRules ().getType ();
9799 return card .getRules ().canBeCommander () || t .isPlaneswalker () || card .getRules ().canBeOathbreaker () || card .getRules ().canBeSignatureSpell ();
98100 };
99101
100- static final Function <PaperCard , Boolean > PLANES_VALIDATOR = card -> {
101- CardType t = card .getRules ().getType ();
102- return t .isPlane () || t .isPhenomenon ();
103- };
104-
105- static final Function <PaperCard , Boolean > DUNGEON_VALIDATOR = card -> {
106- CardType t = card .getRules ().getType ();
107- return t .isDungeon ();
108- };
109-
110- static final Function <PaperCard , Boolean > SCHEME_VALIDATOR = card -> {
111- CardType t = card .getRules ().getType ();
112- return t .isScheme ();
113- };
114-
115- static final Function <PaperCard , Boolean > CONSPIRACY_VALIDATOR = card -> {
116- CardType t = card .getRules ().getType ();
117- return t .isConspiracy ();
118- };
119-
120- static final Function <PaperCard , Boolean > AVATAR_VALIDATOR = card -> {
121- CardType t = card .getRules ().getType ();
122- return t .isVanguard ();
123- };
124-
125- static final Function <PaperCard , Boolean > ATTRACTION_VALIDATOR = card -> {
126- CardType t = card .getRules ().getType ();
127- return t .isAttraction ();
128- };
129-
130- static final Function <PaperCard , Boolean > CONTRAPTION_VALIDATOR = card -> {
131- CardType t = card .getRules ().getType ();
132- return t .isContraption ();
133- };
134-
135102 }
136103}
0 commit comments