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.expression;
24
25 import java.util.List;
26
27 import net.sf.magicproject.clickable.ability.Ability;
28 import net.sf.magicproject.clickable.targetable.Targetable;
29 import net.sf.magicproject.clickable.targetable.card.MCard;
30 import net.sf.magicproject.event.MEventListener;
31 import net.sf.magicproject.event.context.ContextEventListener;
32 import net.sf.magicproject.operation.Operation;
33 import net.sf.magicproject.test.Test;
34
35 /***
36 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
37 * @since 0.80
38 */
39 public class BinaryExpression extends Expression {
40
41 /***
42 * Creates a new instance of BinaryExpression <br>
43 *
44 * @param op
45 * the binart operator
46 * @param left
47 * the left expression of this binary expression
48 * @param right
49 * the right expression of this binary expression
50 */
51 public BinaryExpression(Operation op, Expression left, Expression right) {
52 super();
53 this.op = op;
54 this.left = left;
55 this.right = right;
56 }
57
58 @Override
59 public int getValue(Ability ability, Targetable tested,
60 ContextEventListener context) {
61 return op.process(left.getValue(ability, tested, context), right.getValue(
62 ability, tested, context));
63 }
64
65 @Override
66 public final void extractTriggeredEvents(List<MEventListener> res,
67 MCard source, Test globalTest) {
68 left.extractTriggeredEvents(res, source, globalTest);
69 right.extractTriggeredEvents(res, source, globalTest);
70 }
71
72 /***
73 * The left expression of this expression
74 */
75 private Expression left;
76
77 /***
78 * The right expression of this expression
79 */
80 private Expression right;
81
82 /***
83 * The operation used by this expression
84 */
85 private Operation op;
86
87 }