001    /*
002    // $Id: //open/mondrian/src/main/mondrian/udf/ValUdf.java#3 $
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.Evaluator;
013    import mondrian.olap.Syntax;
014    import mondrian.olap.type.NumericType;
015    import mondrian.olap.type.Type;
016    import mondrian.spi.UserDefinedFunction;
017    
018    /**
019     * VB function <code>Val</code>
020     *
021     * @author Gang Chen
022     */
023    public 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