View Javadoc

1   /*
2    * Created on Nov 8, 2004 
3    * Original filename was BinaryExpression.java
4    * 
5    *   Magic-Project is a turn based strategy simulator
6    *   Copyright (C) 2003-2007 Fabrice Daugan
7    *
8    *   This program is free software; you can redistribute it and/or modify it 
9    * under the terms of the GNU General Public License as published by the Free 
10   * Software Foundation; either version 2 of the License, or (at your option) any
11   * later version.
12   *
13   *   This program is distributed in the hope that it will be useful, but WITHOUT 
14   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
16   * details.
17   *
18   *   You should have received a copy of the GNU General Public License along  
19   * with this program; if not, write to the Free Software Foundation, Inc., 
20   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  }