001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2006-2011 Pentaho and others 008// All Rights Reserved. 009*/ 010package mondrian.udf; 011 012import mondrian.olap.*; 013import mondrian.olap.type.*; 014import mondrian.spi.UserDefinedFunction; 015 016import java.util.List; 017 018/** 019 * User-defined function <code>IN</code>. 020 * 021 * @author schoi 022 */ 023public class InUdf implements UserDefinedFunction { 024 025 public Object execute(Evaluator evaluator, Argument[] arguments) { 026 Object arg0 = arguments[0].evaluate(evaluator); 027 List arg1 = (List) arguments[1].evaluate(evaluator); 028 029 for (Object anArg1 : arg1) { 030 if (((Member) arg0).getUniqueName().equals( 031 ((Member) anArg1).getUniqueName())) 032 { 033 return Boolean.TRUE; 034 } 035 } 036 return Boolean.FALSE; 037 } 038 039 public String getDescription() { 040 return "Returns true if the member argument is contained in the set " 041 + "argument."; 042 } 043 044 public String getName() { 045 return "IN"; 046 } 047 048 public Type[] getParameterTypes() { 049 return new Type[] { 050 MemberType.Unknown, 051 new SetType(MemberType.Unknown) 052 }; 053 } 054 055 public String[] getReservedWords() { 056 // This function does not require any reserved words. 057 return null; 058 } 059 060 public Type getReturnType(Type[] parameterTypes) { 061 return new BooleanType(); 062 } 063 064 public Syntax getSyntax() { 065 return Syntax.Infix; 066 } 067 068} 069 070// End InUdf.java