KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > udf > ValUdf


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/udf/ValUdf.java#3 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2006-2006 Julian Hyde and others
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.udf;
11
12 import mondrian.olap.Evaluator;
13 import mondrian.olap.Syntax;
14 import mondrian.olap.type.NumericType;
15 import mondrian.olap.type.Type;
16 import mondrian.spi.UserDefinedFunction;
17
18 /**
19  * VB function <code>Val</code>
20  *
21  * @author Gang Chen
22  */

23 public class ValUdf implements UserDefinedFunction {
24
25     public Object JavaDoc execute(Evaluator evaluator, Argument[] arguments) {
26         Object JavaDoc arg = arguments[0].evaluateScalar(evaluator);
27
28         if (arg instanceof Number JavaDoc) {
29             return new Double JavaDoc(((Number JavaDoc) arg).doubleValue());
30         } else {
31             return new Double JavaDoc(0.0);
32         }
33     }
34
35     public String JavaDoc getDescription() {
36         return "VB function Val";
37     }
38
39     public String JavaDoc getName() {
40         return "Val";
41     }
42
43     public Type[] getParameterTypes() {
44         return new Type[] { new NumericType() };
45     }
46
47     public String JavaDoc[] getReservedWords() {
48         return null;
49     }
50
51     public Type getReturnType(Type[] parameterTypes) {
52         return new NumericType();
53     }
54
55     public Syntax getSyntax() {
56         return Syntax.Function;
57     }
58
59 }
60
61 // End ValUdf.java
62
Popular Tags