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 comparison between two values.
10: */
11: public class Compare extends BinaryValueOperator {
12:
13: /*---------------*
14: * enum Operator *
15: *---------------*/
16:
17: public enum CompareOp {
18: /** equal to */
19: EQ("="),
20:
21: /** not equal to */
22: NE("!="),
23:
24: /** lower than */
25: LT("<"),
26:
27: /** lower than or equal to */
28: LE("<="),
29:
30: /** greater than or equal to */
31: GE(">="),
32:
33: /** greater than */
34: GT(">");
35:
36: private String symbol;
37:
38: CompareOp(String symbol) {
39: this .symbol = symbol;
40: }
41:
42: public String getSymbol() {
43: return symbol;
44: }
45: }
46:
47: /*-----------*
48: * Variables *
49: *-----------*/
50:
51: private CompareOp operator;
52:
53: /*--------------*
54: * Constructors *
55: *--------------*/
56:
57: public Compare() {
58: }
59:
60: public Compare(ValueExpr leftArg, ValueExpr rightArg) {
61: this (leftArg, rightArg, CompareOp.EQ);
62: }
63:
64: public Compare(ValueExpr leftArg, ValueExpr rightArg,
65: CompareOp operator) {
66: super (leftArg, rightArg);
67: setOperator(operator);
68: }
69:
70: /*---------*
71: * Methods *
72: *---------*/
73:
74: public CompareOp getOperator() {
75: return operator;
76: }
77:
78: public void setOperator(CompareOp operator) {
79: assert operator != null : "operator must not be null";
80: this .operator = operator;
81: }
82:
83: public <X extends Exception> void visit(QueryModelVisitor<X> visitor)
84: throws X {
85: visitor.meet(this );
86: }
87:
88: @Override
89: public String getSignature() {
90: return super .getSignature() + " (" + operator.getSymbol() + ")";
91: }
92:
93: @Override
94: public Compare clone() {
95: return (Compare) super.clone();
96: }
97: }
|