01: package org.osbl.agent.model.condition;
02:
03: /**
04: * This kind of Operator defines a binary operator, as in leftOperand OPERATOR rightOperand.
05: *
06: * For example, in the expression: price > 30, then the ">" would be defined by one instance
07: * of this class.
08: *
09: * The expression for evaluation is constructed in this same spirit.
10: *
11: * @author Sebastian Nozzi.
12: */
13: public class BinaryOperator extends Operator {
14:
15: /**
16: * Instantiates a new binary operator.
17: */
18: public BinaryOperator() {
19: }
20:
21: /**
22: * Instantiates a new binary operator with a operator as a String.
23: * The label will be taken from the String as well.
24: *
25: * @param operatorString the operator string
26: */
27: public BinaryOperator(String operatorString) {
28: this (operatorString, operatorString);
29: }
30:
31: /**
32: * Instantiates a new binary operator with an operator as String and a label.
33: * This allows the definition of Operators like "==", and show (in the UI) a
34: * text like "equals".
35: *
36: * @param label the label
37: * @param operatorCode the operator code
38: */
39: public BinaryOperator(String label, String operatorCode) {
40: super (label, operatorCode);
41: }
42:
43: /**
44: * The implementation for this class builds the expression as in:
45: *
46: * left operatorCode right
47: *
48: * For example:
49: *
50: * price >= 30
51: *
52: * where "price" was the left part, "30" was the right part, and ">=" the operatorCode.
53: *
54: * @param left the left
55: * @param right the right
56: *
57: * @return the expression
58: *
59: * @see org.osbl.agent.model.condition.Operator#getExpression(java.lang.String, java.lang.String)
60: */
61: protected String getExpression(String left, String right) {
62:
63: // Construct the expression as in a normal binary operator.
64: return left + this.getOperatorCode() + right;
65: }
66:
67: }
|