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.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 }