KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > udf > MatchesUdf


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/udf/MatchesUdf.java#1 $
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>MATCHES</code>.
22  *
23  * @author schoi
24  * @version $Id: //open/mondrian/src/main/mondrian/udf/MatchesUdf.java#1 $
25  */

26 public class MatchesUdf implements UserDefinedFunction {
27
28     public Object JavaDoc execute(Evaluator evaluator, Argument[] arguments) {
29
30         Object JavaDoc arg0 = arguments[0].evaluateScalar(evaluator);
31         Object JavaDoc arg1 = arguments[1].evaluateScalar(evaluator);
32
33         return Boolean.valueOf(Pattern.matches((String JavaDoc)arg1, (String JavaDoc)arg0));
34     }
35
36     public String JavaDoc getDescription() {
37         return "Returns true if the string matches the regular expression.";
38     }
39
40     public String JavaDoc getName() {
41         return "MATCHES";
42     }
43
44     public Type[] getParameterTypes() {
45         return new Type[] {
46             new StringType(),
47             new StringType()
48         };
49     }
50
51     public String JavaDoc[] getReservedWords() {
52         // This function does not require any reserved words.
53
return null;
54     }
55
56     public Type getReturnType(Type[] parameterTypes) {
57         return new BooleanType();
58     }
59
60     public Syntax getSyntax() {
61         return Syntax.Infix;
62     }
63
64 }
65
66 // End MatchesUdf.java
67
Popular Tags