01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.query.algebra;
07:
08: /**
09: * A mathematical expression consisting an operator and two arguments.
10: */
11: public class MathExpr extends BinaryValueOperator {
12:
13: /*---------------*
14: * enum Operator *
15: *---------------*/
16:
17: public enum MathOp {
18: PLUS("+"), MINUS("-"), MULTIPLY("*"), DIVIDE("/");
19:
20: private String symbol;
21:
22: MathOp(String symbol) {
23: this .symbol = symbol;
24: }
25:
26: public String getSymbol() {
27: return symbol;
28: }
29: }
30:
31: /*-----------*
32: * Variables *
33: *-----------*/
34:
35: private MathOp operator;
36:
37: /*--------------*
38: * Constructors *
39: *--------------*/
40:
41: public MathExpr() {
42: }
43:
44: public MathExpr(ValueExpr leftArg, ValueExpr rightArg,
45: MathOp operator) {
46: super (leftArg, rightArg);
47: setOperator(operator);
48: }
49:
50: /*---------*
51: * Methods *
52: *---------*/
53:
54: public MathOp getOperator() {
55: return operator;
56: }
57:
58: public void setOperator(MathOp operator) {
59: assert operator != null : "operator must not be null";
60: this .operator = operator;
61: }
62:
63: public <X extends Exception> void visit(QueryModelVisitor<X> visitor)
64: throws X {
65: visitor.meet(this );
66: }
67:
68: @Override
69: public String getSignature() {
70: return super .getSignature() + " (" + operator.getSymbol() + ")";
71: }
72:
73: @Override
74: public MathExpr clone() {
75: return (MathExpr) super.clone();
76: }
77: }
|