KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > ejb > query > NumericFunctionNode


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.ejb.query;
13
14 /**
15  * Functions that return numerics.
16  */

17 public class NumericFunctionNode extends Node {
18
19     public static final int LENGTH = 1;
20     public static final int LOCATE = 2;
21     public static final int ABS = 3;
22     public static final int SQRT = 4;
23     public static final int MOD = 5;
24     public static final int BIT_LENGTH = 6;
25
26     private int function;
27     private Node args;
28
29     public NumericFunctionNode(int function, Node args) {
30         this.function = function;
31         this.args = args;
32     }
33
34     public int getFunction() {
35         return function;
36     }
37
38     public Node getArgs() {
39         return args;
40     }
41
42     public String JavaDoc getFunctionStr() {
43         switch (function) {
44             case LENGTH: return "LENGTH";
45             case LOCATE: return "LOCATE";
46             case ABS: return "ABS";
47             case SQRT: return "SQRT";
48             case MOD: return "MOD";
49             case BIT_LENGTH: return "BIT_LENGTH";
50         }
51         return "<? function " + function + " ?>";
52     }
53
54     public Object JavaDoc arrive(NodeVisitor v, Object JavaDoc msg) {
55         return v.arriveNumericFunctionNode(this, msg);
56     }
57
58     public String JavaDoc toStringImp() {
59         StringBuffer JavaDoc s = new StringBuffer JavaDoc();
60         s.append(getFunctionStr());
61         s.append('(');
62         if (args != null) {
63             args.appendList(s);
64         }
65         s.append(')');
66         return s.toString();
67     }
68
69     public void resolve(ResolveContext rc) {
70         args.resolve(rc);
71     }
72
73 }
74
75
Popular Tags