KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > query > CompareOpNode


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo.query;
13
14 import com.versant.core.common.BindingSupportImpl;
15
16 /**
17  * A comparision operation (other than equals and not equals).
18  */

19 public class CompareOpNode extends BinaryNode {
20
21     public static final int GT = 1;
22     public static final int LT = 2;
23     public static final int GE = 3;
24     public static final int LE = 4;
25
26     /**
27      * The operation.
28      */

29     public int op;
30
31     public CompareOpNode(Node left, Node right, int op) {
32         super(left, right);
33         this.op = op;
34     }
35
36     public Object JavaDoc accept(NodeVisitor visitor, Object JavaDoc[] results) {
37       return visitor.visitCompareOpNode(this, results);
38     }
39
40     public String JavaDoc toString() {
41         return super.toString() + " " + toOpString(op);
42     }
43
44     public static String JavaDoc toOpString(int op) {
45         switch (op) {
46             case GT: return ">";
47             case LT: return "<";
48             case GE: return ">=";
49             case LE: return "<=";
50         }
51         return "Unknown(" + op + ")";
52     }
53
54     /**
55      * Swap left and right nodes.
56      */

57     protected void swapLeftAndRight() {
58         super.swapLeftAndRight();
59         switch (op) {
60             case GT: op = LT; break;
61             case LT: op = GT; break;
62             case GE: op = LE; break;
63             case LE: op = GE; break;
64             default:
65                 throw BindingSupportImpl.getInstance().internal("Unknown op: " +
66                     toOpString(op));
67         }
68     }
69
70     public Field visit(MemVisitor visitor, Object JavaDoc obj) {
71         return visitor.visitCompareOpNode(this, obj);
72     }
73
74     public Object JavaDoc arrive(NodeVisitor v, Object JavaDoc msg) {
75         return v.arriveCompareOpNode(this, msg);
76     }
77
78 }
79
80
Popular Tags