KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > udf > InUdf


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/udf/InUdf.java#2 $
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.*;
13 import mondrian.olap.type.*;
14 import mondrian.spi.UserDefinedFunction;
15 import mondrian.util.*;
16
17 import java.util.*;
18 import java.util.regex.*;
19
20 /**
21  * User-defined function <code>IN</code>.
22  *
23  * @author schoi
24  * @version $Id: //open/mondrian/src/main/mondrian/udf/InUdf.java#2 $
25  */

26 public class InUdf implements UserDefinedFunction {
27
28     public Object JavaDoc execute(Evaluator evaluator, Argument[] arguments) {
29
30         Object JavaDoc arg0 = arguments[0].evaluate(evaluator);
31         List arg1 = (List) arguments[1].evaluate(evaluator);
32
33         for (Object JavaDoc anArg1 : arg1) {
34             if (((Member) arg0).getUniqueName().equals(
35                 ((Member) anArg1).getUniqueName())) {
36                 return Boolean.TRUE;
37             }
38         }
39         return Boolean.FALSE;
40     }
41
42     public String JavaDoc getDescription() {
43         return "Returns true if the member argument is contained in the set argument.";
44     }
45
46     public String JavaDoc getName() {
47         return "IN";
48     }
49
50     public Type[] getParameterTypes() {
51         return new Type[] {
52             MemberType.Unknown,
53             new SetType(MemberType.Unknown)
54         };
55     }
56
57     public String JavaDoc[] getReservedWords() {
58         // This function does not require any reserved words.
59
return null;
60     }
61
62     public Type getReturnType(Type[] parameterTypes) {
63         return new BooleanType();
64     }
65
66     public Syntax getSyntax() {
67         return Syntax.Infix;
68     }
69
70 }
71
72 // End InUdf.java
73
Popular Tags