View Javadoc

1   /*
2    * Sup.java 
3    * Created on 25 feb. 2004
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  package net.sf.magicproject.test;
23  
24  import java.io.IOException;
25  import java.io.InputStream;
26  import java.util.Map;
27  
28  import net.sf.magicproject.annotation.XmlTestElement;
29  import net.sf.magicproject.clickable.ability.Ability;
30  import net.sf.magicproject.clickable.targetable.Targetable;
31  import net.sf.magicproject.expression.Expression;
32  
33  /***
34   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
35   * @since 0.54
36   */
37  @XmlTestElement(id = IdTest.SUP)
38  public class Sup extends TestExpr {
39  
40  	/***
41  	 * Create an instance of Sup by reading a file. Offset's file must pointing on
42  	 * the first byte of this test <br>
43  	 * <ul>
44  	 * Structure of InputStream : Data[size]
45  	 * <li>left value,idToken [2]</li>
46  	 * <li>right value, idToken [2]</li>
47  	 * </ul>
48  	 * 
49  	 * @param inputFile
50  	 *          is the file containing this event
51  	 * @throws IOException
52  	 *           if error occurred during the reading process from the specified
53  	 *           input stream
54  	 */
55  	Sup(InputStream inputFile) throws IOException {
56  		super(inputFile);
57  	}
58  
59  	/***
60  	 * Create a new instance of Sup given left and right expression.
61  	 * 
62  	 * @param leftExpression
63  	 *          the left expression of this test.
64  	 * @param rightExpression
65  	 *          the right expression of this test.
66  	 */
67  	private Sup(Expression leftExpression, Expression rightExpression) {
68  		super(leftExpression, rightExpression);
69  	}
70  
71  	@Override
72  	public Test getConstraintTest(Map<String, Expression> values) {
73  		return new Sup(leftExpression.getConstraintExpression(values),
74  				rightExpression.getConstraintExpression(values));
75  	}
76  
77  	@Override
78  	public boolean test(Ability ability, Targetable tested) {
79  		return getLeftValue(ability, tested) > getRightValue(ability, tested);
80  	}
81  
82  	@Override
83  	public String toString() {
84  		return "(" + leftExpression.toString() + " > " + rightExpression.toString()
85  				+ ")";
86  	}
87  }