View Javadoc

1   /*
2    * 
3    *   Magic-Project is a turn based strategy simulator
4    *   Copyright (C) 2003-2007 Fabrice Daugan
5    *
6    *   This program is free software; you can redistribute it and/or modify it 
7    * under the terms of the GNU General Public License as published by the Free 
8    * Software Foundation; either version 2 of the License, or (at your option) any
9    * later version.
10   *
11   *   This program is distributed in the hope that it will be useful, but WITHOUT 
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
14   * details.
15   *
16   *   You should have received a copy of the GNU General Public License along  
17   * with this program; if not, write to the Free Software Foundation, Inc., 
18   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package net.sf.magicproject.test;
21  
22  import java.io.IOException;
23  import java.io.InputStream;
24  
25  import net.sf.magicproject.clickable.ability.Ability;
26  import net.sf.magicproject.clickable.targetable.Targetable;
27  import net.sf.magicproject.tools.MToolKit;
28  
29  /***
30   * Test if the tested targetable contains the given private named targetable.
31   * 
32   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
33   * @since 0.90
34   */
35  class HasPrivateObject extends TestObject {
36  
37  	/***
38  	 * Create an instance of HasPrivateNamedTargetable by reading a file. Offset's
39  	 * file must pointing on the first byte of this test <br>
40  	 * <ul>
41  	 * Structure of InputStream : Data[size]
42  	 * <li>idTest [1]</li>
43  	 * <li>used targetable for test [1]
44  	 * <li>named targetable + '\0' : String [...]</li>
45  	 * </ul>
46  	 * 
47  	 * @param inputFile
48  	 *          is the file containing this event
49  	 * @throws IOException
50  	 *           if error occurred during the reading process from the specified
51  	 *           input stream
52  	 */
53  	HasPrivateObject(InputStream inputFile) throws IOException {
54  		super(inputFile);
55  		privateNamedTargetable = MToolKit.readString(inputFile);
56  	}
57  
58  	@Override
59  	public final boolean test(Ability ability, Targetable tested) {
60  		return on.getTargetable(ability, tested).getPrivateNamedObject(
61  				privateNamedTargetable) != null;
62  	}
63  
64  	/***
65  	 * The name of looked for targetable.
66  	 */
67  	protected String privateNamedTargetable;
68  
69  }