01: package org.ofbiz.rules.logikus;
02:
03: import org.ofbiz.rules.parse.*;
04: import org.ofbiz.rules.engine.*;
05:
06: /**
07: * <p><b>Title:</b> Arithmetic Assembler
08: * <p><b>Description:</b> None
09: * <p>Copyright (c) 1999 Steven J. Metsker.
10: * <p>Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
11: *
12: * <p>Permission is hereby granted, free of charge, to any person obtaining a
13: * copy of this software and associated documentation files (the "Software"),
14: * to deal in the Software without restriction, including without limitation
15: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16: * and/or sell copies of the Software, and to permit persons to whom the
17: * Software is furnished to do so, subject to the following conditions:
18: *
19: * <p>The above copyright notice and this permission notice shall be included
20: * in all copies or substantial portions of the Software.
21: *
22: * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
27: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
28: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29: *
30: * <br>
31: * <p>This assembler pops two arithmetic operands, builds an
32: * ArithmeticOperator from them, and pushes it.
33: *
34: * @author Steven J. Metsker
35: * @version 1.0
36: */
37: public class ArithmeticAssembler extends Assembler {
38:
39: /**
40: * the character which represents an arithmetic operator
41: */
42: protected char operator;
43:
44: /**
45: * Constructs an assembler that will stack an
46: * ArithmeticOperator with the specified operator.
47: */
48: public ArithmeticAssembler(char operator) {
49: this .operator = operator;
50: }
51:
52: /**
53: * Pop two arithmetic operands, build an ArithmeticOperator
54: * from them, and push it.
55: *
56: * @param Assembly the assembly to work on
57: */
58: public void workOn(Assembly a) {
59: ArithmeticTerm operand1 = (ArithmeticTerm) a.pop();
60: ArithmeticTerm operand0 = (ArithmeticTerm) a.pop();
61:
62: a.push(new ArithmeticOperator(operator, operand0, operand1));
63: }
64: }
|