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-2006 Pentaho and others 008// All Rights Reserved. 009*/ 010package mondrian.udf; 011 012import mondrian.olap.Evaluator; 013import mondrian.olap.Syntax; 014import mondrian.olap.type.NumericType; 015import mondrian.olap.type.Type; 016import mondrian.spi.UserDefinedFunction; 017 018/** 019 * VB function <code>Val</code> 020 * 021 * @author Gang Chen 022 */ 023public class ValUdf implements UserDefinedFunction { 024 025 public Object execute(Evaluator evaluator, Argument[] arguments) { 026 Object arg = arguments[0].evaluateScalar(evaluator); 027 028 if (arg instanceof Number) { 029 return new Double(((Number) arg).doubleValue()); 030 } else { 031 return new Double(0.0); 032 } 033 } 034 035 public String getDescription() { 036 return "VB function Val"; 037 } 038 039 public String getName() { 040 return "Val"; 041 } 042 043 public Type[] getParameterTypes() { 044 return new Type[] { new NumericType() }; 045 } 046 047 public String[] getReservedWords() { 048 return null; 049 } 050 051 public Type getReturnType(Type[] parameterTypes) { 052 return new NumericType(); 053 } 054 055 public Syntax getSyntax() { 056 return Syntax.Function; 057 } 058 059} 060 061// End ValUdf.java