View Javadoc

1   /*
2    * Created on Aug 31, 2004 
3    * Original filename was Add.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.operation;
24  
25  /***
26   * Reprsents the PLUS operation. This operation is optimzed since it is not
27   * executed is is useless.
28   * 
29   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
30   * @since 0.71
31   */
32  public final class Add extends BinaryOperation {
33  
34  	/***
35  	 * Creates a new instance of Add <br>
36  	 */
37  	private Add() {
38  		super();
39  	}
40  
41  	@Override
42  	public int process(int leftValue, int rightValue) {
43  		return leftValue + rightValue;
44  	}
45  
46  	@Override
47  	public boolean isUselessWith(int leftValue, int rightValue) {
48  		return super.isUselessWith(leftValue, rightValue) || rightValue <= 0;
49  	}
50  
51  	@Override
52  	public String getOperator() {
53  		return "add";
54  	}
55  
56  	/***
57  	 * Return the unique instance of this operation.
58  	 * 
59  	 * @return the unique instance of this operation.
60  	 */
61  	public static Operation getInstance() {
62  		if (instance == null) {
63  			instance = new Add();
64  		}
65  		return instance;
66  	}
67  
68  	/***
69  	 * The unique instance of this operation
70  	 */
71  	private static Operation instance = null;
72  }