001 /*
002 // $Id: //open/mondrian-release/3.0/src/main/mondrian/udf/InUdf.java#2 $
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>IN</code>.
022 *
023 * @author schoi
024 * @version $Id: //open/mondrian-release/3.0/src/main/mondrian/udf/InUdf.java#2 $
025 */
026 public class InUdf implements UserDefinedFunction {
027
028 public Object execute(Evaluator evaluator, Argument[] arguments) {
029
030 Object arg0 = arguments[0].evaluate(evaluator);
031 List arg1 = (List) arguments[1].evaluate(evaluator);
032
033 for (Object anArg1 : arg1) {
034 if (((Member) arg0).getUniqueName().equals(
035 ((Member) anArg1).getUniqueName())) {
036 return Boolean.TRUE;
037 }
038 }
039 return Boolean.FALSE;
040 }
041
042 public String getDescription() {
043 return "Returns true if the member argument is contained in the set argument.";
044 }
045
046 public String getName() {
047 return "IN";
048 }
049
050 public Type[] getParameterTypes() {
051 return new Type[] {
052 MemberType.Unknown,
053 new SetType(MemberType.Unknown)
054 };
055 }
056
057 public String[] getReservedWords() {
058 // This function does not require any reserved words.
059 return null;
060 }
061
062 public Type getReturnType(Type[] parameterTypes) {
063 return new BooleanType();
064 }
065
066 public Syntax getSyntax() {
067 return Syntax.Infix;
068 }
069
070 }
071
072 // End InUdf.java