Skip to content

Commit d1f190a

Browse files
committed
apply review
1 parent 19b8a80 commit d1f190a

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

Mage/src/main/java/mage/filter/FilterCard.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public void add(ObjectSourcePlayerPredicate predicate) {
7373

7474
@Override
7575
public boolean checkObjectClass(Object object) {
76+
// TODO: investigate if we can/should exclude Permanent here.
77+
// as it does extend Card (if so do cleanup the
78+
// MultiFilterImpl that match Permanent and Card/Spell)
7679
return object instanceof Card;
7780
}
7881
}

Mage/src/main/java/mage/filter/FilterImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public FilterImpl(String name) {
3434
protected FilterImpl(final FilterImpl<E> filter) {
3535
this.message = filter.message;
3636
this.predicates = new ArrayList<>(filter.predicates);
37-
this.extraPredicates.addAll(filter.extraPredicates);
37+
this.extraPredicates = new ArrayList<>(filter.extraPredicates);
3838
this.lockedFilter = false;// After copying a filter it's allowed to modify
3939
}
4040

@@ -46,6 +46,7 @@ public boolean match(E e, Game game) {
4646
return false;
4747
}
4848

49+
@Override
4950
public boolean match(E object, UUID sourceControllerId, Ability source, Game game) {
5051
if (!this.match(object, game)) {
5152
return false;

Mage/src/main/java/mage/filter/MultiFilterImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
/**
1515
* Make a Filter out of multiple inner filters.
16+
* If making a multi filter out of filterA and filterB,
17+
* any object match the multi filter if it either match
18+
* filterA or match filterB.
1619
*
1720
* @author Susucr
1821
*/
@@ -26,6 +29,9 @@ public abstract class MultiFilterImpl<E> implements Filter<E> {
2629

2730
protected MultiFilterImpl(String name, Filter<? extends E>... filters) {
2831
this.message = name;
32+
if (filters.length < 2) {
33+
throw new IllegalArgumentException("Wrong code usage: MultiFilterImpl should have at least 2 inner filters");
34+
}
2935
this.innerFilters.addAll(Arrays.stream(filters).collect(Collectors.toList()));
3036
}
3137

@@ -43,6 +49,7 @@ public boolean match(E object, Game game) {
4349
.anyMatch((Filter filter) -> filter.match(object, game));
4450
}
4551

52+
@Override
4653
public boolean match(E object, UUID sourceControllerId, Ability source, Game game) {
4754
return innerFilters
4855
.stream()

Mage/src/main/java/mage/filter/common/FilterPermanentOrSuspendedCard.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package mage.filter.common;
22

33
import mage.MageObject;
4+
import mage.abilities.Ability;
45
import mage.abilities.keyword.SuspendAbility;
6+
import mage.cards.Card;
57
import mage.counters.CounterType;
68
import mage.filter.FilterCard;
79
import mage.filter.FilterPermanent;
810
import mage.filter.MultiFilterImpl;
911
import mage.filter.predicate.mageobject.AbilityPredicate;
12+
import mage.game.Game;
13+
import mage.game.permanent.Permanent;
14+
15+
import java.util.UUID;
1016

1117
/**
1218
* @author emerald000
@@ -27,6 +33,32 @@ protected FilterPermanentOrSuspendedCard(final FilterPermanentOrSuspendedCard fi
2733
super(filter);
2834
}
2935

36+
@Override
37+
public boolean match(MageObject object, Game game) {
38+
// We can not rely on super.match, since Permanent extend Card
39+
// so a Permanent could get filtered by the FilterCard
40+
if (object instanceof Permanent) {
41+
return getPermanentFilter().match((Permanent) object, game);
42+
} else if (object instanceof Card) {
43+
return getCardFilter().match((Card) object, game);
44+
} else {
45+
return false;
46+
}
47+
}
48+
49+
@Override
50+
public boolean match(MageObject object, UUID sourceControllerId, Ability source, Game game) {
51+
// We can not rely on super.match, since Permanent extend Card
52+
// so a Permanent could get filtered by the FilterCard
53+
if (object instanceof Permanent) {
54+
return getPermanentFilter().match((Permanent) object, sourceControllerId, source, game);
55+
} else if (object instanceof Card) {
56+
return getCardFilter().match((Card) object, sourceControllerId, source, game);
57+
} else {
58+
return false;
59+
}
60+
}
61+
3062
@Override
3163
public FilterPermanentOrSuspendedCard copy() {
3264
return new FilterPermanentOrSuspendedCard(this);

Mage/src/main/java/mage/filter/common/FilterSpellOrPermanent.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package mage.filter.common;
22

33
import mage.MageObject;
4+
import mage.abilities.Ability;
45
import mage.filter.FilterPermanent;
56
import mage.filter.FilterSpell;
67
import mage.filter.MultiFilterImpl;
8+
import mage.game.Game;
9+
import mage.game.permanent.Permanent;
10+
import mage.game.stack.Spell;
11+
12+
import java.util.UUID;
713

814
/**
915
* @author LevelX
@@ -22,6 +28,33 @@ protected FilterSpellOrPermanent(final FilterSpellOrPermanent filter) {
2228
super(filter);
2329
}
2430

31+
32+
@Override
33+
public boolean match(MageObject object, Game game) {
34+
// We can not rely on super.match, since Permanent extend Card
35+
// and currently FilterSpell accepts to filter Cards
36+
if (object instanceof Permanent) {
37+
return getPermanentFilter().match((Permanent) object, game);
38+
} else if (object instanceof Spell) {
39+
return getSpellFilter().match((Spell) object, game);
40+
} else {
41+
return false;
42+
}
43+
}
44+
45+
@Override
46+
public boolean match(MageObject object, UUID sourceControllerId, Ability source, Game game) {
47+
// We can not rely on super.match, since Permanent extend Card
48+
// and currently FilterSpell accepts to filter Cards
49+
if (object instanceof Permanent) {
50+
return getPermanentFilter().match((Permanent) object, sourceControllerId, source, game);
51+
} else if (object instanceof Spell) {
52+
return getSpellFilter().match((Spell) object, sourceControllerId, source, game);
53+
} else {
54+
return false;
55+
}
56+
}
57+
2558
@Override
2659
public FilterSpellOrPermanent copy() {
2760
return new FilterSpellOrPermanent(this);

0 commit comments

Comments
 (0)