01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdo.query;
12:
13: import com.versant.core.common.BindingSupportImpl;
14:
15: /**
16: * A comparision operation (other than equals and not equals).
17: */
18: public class CompareOpNode extends BinaryNode {
19:
20: public static final int GT = 1;
21: public static final int LT = 2;
22: public static final int GE = 3;
23: public static final int LE = 4;
24:
25: /**
26: * The operation.
27: */
28: public int op;
29:
30: public CompareOpNode(Node left, Node right, int op) {
31: super (left, right);
32: this .op = op;
33: }
34:
35: public Object accept(NodeVisitor visitor, Object[] results) {
36: return visitor.visitCompareOpNode(this , results);
37: }
38:
39: public String toString() {
40: return super .toString() + " " + toOpString(op);
41: }
42:
43: public static String toOpString(int op) {
44: switch (op) {
45: case GT:
46: return ">";
47: case LT:
48: return "<";
49: case GE:
50: return ">=";
51: case LE:
52: return "<=";
53: }
54: return "Unknown(" + op + ")";
55: }
56:
57: /**
58: * Swap left and right nodes.
59: */
60: protected void swapLeftAndRight() {
61: super .swapLeftAndRight();
62: switch (op) {
63: case GT:
64: op = LT;
65: break;
66: case LT:
67: op = GT;
68: break;
69: case GE:
70: op = LE;
71: break;
72: case LE:
73: op = GE;
74: break;
75: default:
76: throw BindingSupportImpl.getInstance().internal(
77: "Unknown op: " + toOpString(op));
78: }
79: }
80:
81: public Field visit(MemVisitor visitor, Object obj) {
82: return visitor.visitCompareOpNode(this , obj);
83: }
84:
85: public Object arrive(NodeVisitor v, Object msg) {
86: return v.arriveCompareOpNode(this, msg);
87: }
88:
89: }
|