1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.magicproject.test;
24
25 import java.io.IOException;
26 import java.io.InputStream;
27
28 import net.sf.magicproject.clickable.ability.Ability;
29 import net.sf.magicproject.clickable.targetable.card.MCard;
30
31 /***
32 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
33 * @since 0.80
34 * @since 0.91 an additional component 'other' is used.
35 */
36 public class IsTested extends TestCard {
37
38 /***
39 * The other component to test
40 */
41 private final TestOn other;
42
43 /***
44 * Create an instance of IsTested by reading a file. Offset's file must
45 * pointing on the first byte of this test <br>
46 * <ul>
47 * Structure of InputStream : Data[size]
48 * <li>card TestOn [1]</li>
49 * <li>other TestOn [1]</li>
50 * </ul>
51 *
52 * @param inputFile
53 * is the file containing this event
54 * @throws IOException
55 * if error occurred during the reading process from the specified
56 * input stream
57 */
58 protected IsTested(InputStream inputFile) throws IOException {
59 super(inputFile);
60 other = TestOn.deserialize(inputFile);
61 }
62
63 /***
64 * Create an instance of TestedIsMe <br>
65 *
66 * @param on
67 * the card that would be compared to the tesed one.
68 */
69 public IsTested(TestOn on) {
70 this(on, TestOn.TESTED);
71 }
72
73 /***
74 * Create an instance of TestedIsMe <br>
75 *
76 * @param on
77 * the card that would be compared to the tesed one.
78 * @param other
79 * The other component to test.
80 */
81 public IsTested(TestOn on, TestOn other) {
82 super(on);
83 this.other = other;
84 }
85
86 @Override
87 public boolean testCard(Ability ability, MCard tested) {
88 return other.getTargetable(ability, tested) == on.getTargetable(ability,
89 tested);
90 }
91
92 /***
93 * Default instance representing the test against ME and TESTED.
94 */
95 public static final IsTested TESTED_IS_ME = new IsTested(TestOn.THIS);
96
97 /***
98 * Default instance representing the test against ATTACHED_TO and TESTED.
99 */
100 public static final Test TESTED_IS_ATTACHED_TO = new IsTested(TestOn.TESTED,
101 TestOn.ATTACHED_TO);
102
103 }