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.io.IOException;
26 import java.io.InputStream;
27 import java.util.List;
28
29 import net.sf.magicproject.clickable.ability.Ability;
30 import net.sf.magicproject.clickable.targetable.Targetable;
31 import net.sf.magicproject.clickable.targetable.card.MCard;
32 import net.sf.magicproject.event.MEventListener;
33 import net.sf.magicproject.event.context.ContextEventListener;
34 import net.sf.magicproject.operation.Operation;
35 import net.sf.magicproject.test.Test;
36
37 /***
38 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
39 * @since 0.80
40 */
41 public class UnaryExpression extends Expression {
42
43 /***
44 * Creates a new instance of UnaryExpression <br>
45 *
46 * @param op
47 * the operation used by this expression.
48 * @param expr
49 * the expression used for this expression
50 */
51 public UnaryExpression(Operation op, Expression expr) {
52 super();
53 this.op = op;
54 this.expr = expr;
55 }
56
57 /***
58 * Create a new instance of this class.
59 *
60 * @param inputFile
61 * file containing this action
62 * @param op
63 * optional operation.
64 * @throws IOException
65 * if error occurred during the reading process from the specified
66 * input stream
67 */
68
69 public UnaryExpression(InputStream inputFile, Operation op)
70 throws IOException {
71 expr = ExpressionFactory.readNextExpression(inputFile);
72 this.op = op;
73 }
74
75 @Override
76 public int getValue(Ability ability, Targetable tested,
77 ContextEventListener context) {
78 return op.process(expr.getValue(ability, tested, context), 0);
79 }
80
81 @Override
82 public void extractTriggeredEvents(List<MEventListener> res, MCard source,
83 Test globalTest) {
84 expr.extractTriggeredEvents(res, source, globalTest);
85 }
86
87 @Override
88 public boolean canBePreempted() {
89 return expr.canBePreempted();
90 }
91
92 /***
93 * The operation used by this expression
94 */
95 private final Operation op;
96
97 /***
98 * The expression used for this expression
99 */
100 protected final Expression expr;
101
102 }