001 /* 002 // $Id: //open/mondrian/src/main/mondrian/udf/MatchesUdf.java#1 $ 003 // This software is subject to the terms of the Common Public License 004 // Agreement, available at the following URL: 005 // http://www.opensource.org/licenses/cpl.html. 006 // Copyright (C) 2006-2006 Julian Hyde and others 007 // All Rights Reserved. 008 // You must accept the terms of that agreement to use this software. 009 */ 010 package mondrian.udf; 011 012 import mondrian.olap.*; 013 import mondrian.olap.type.*; 014 import mondrian.spi.UserDefinedFunction; 015 import mondrian.util.*; 016 017 import java.util.*; 018 import java.util.regex.*; 019 020 /** 021 * User-defined function <code>MATCHES</code>. 022 * 023 * @author schoi 024 * @version $Id: //open/mondrian/src/main/mondrian/udf/MatchesUdf.java#1 $ 025 */ 026 public class MatchesUdf implements UserDefinedFunction { 027 028 public Object execute(Evaluator evaluator, Argument[] arguments) { 029 030 Object arg0 = arguments[0].evaluateScalar(evaluator); 031 Object arg1 = arguments[1].evaluateScalar(evaluator); 032 033 return Boolean.valueOf(Pattern.matches((String)arg1, (String)arg0)); 034 } 035 036 public String getDescription() { 037 return "Returns true if the string matches the regular expression."; 038 } 039 040 public String getName() { 041 return "MATCHES"; 042 } 043 044 public Type[] getParameterTypes() { 045 return new Type[] { 046 new StringType(), 047 new StringType() 048 }; 049 } 050 051 public String[] getReservedWords() { 052 // This function does not require any reserved words. 053 return null; 054 } 055 056 public Type getReturnType(Type[] parameterTypes) { 057 return new BooleanType(); 058 } 059 060 public Syntax getSyntax() { 061 return Syntax.Infix; 062 } 063 064 } 065 066 // End MatchesUdf.java