/libformula-1.1.3/source/org/pentaho/reporting/libraries/formula/function/information/IsBlankFunction.java
Java | 74 lines | 44 code | 9 blank | 21 comment | 4 complexity | df5aacd24aa18dbbe8b5df0c36584a37 MD5 | raw file
Possible License(s): LGPL-2.1
1/*
2 * This program is free software; you can redistribute it and/or modify it under the
3 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
4 * Foundation.
5 *
6 * You should have received a copy of the GNU Lesser General Public License along with this
7 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
8 * or from the Free Software Foundation, Inc.,
9 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU Lesser General Public License for more details.
14 *
15 * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved.
16 */
17
18package org.pentaho.reporting.libraries.formula.function.information;
19
20import org.pentaho.reporting.libraries.formula.EvaluationException;
21import org.pentaho.reporting.libraries.formula.FormulaContext;
22import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue;
23import org.pentaho.reporting.libraries.formula.function.Function;
24import org.pentaho.reporting.libraries.formula.function.ParameterCallback;
25import org.pentaho.reporting.libraries.formula.lvalues.ContextLookup;
26import org.pentaho.reporting.libraries.formula.lvalues.LValue;
27import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair;
28import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType;
29
30/**
31 * Document me!
32 *
33 * @author : Thomas Morgner
34 */
35public class IsBlankFunction implements Function
36{
37 private static final TypeValuePair RETURN_FALSE = new TypeValuePair(
38 LogicalType.TYPE, Boolean.FALSE);
39
40 private static final TypeValuePair RETURN_TRUE = new TypeValuePair(
41 LogicalType.TYPE, Boolean.TRUE);
42 private static final long serialVersionUID = 3352413434463488403L;
43
44 public IsBlankFunction()
45 {
46 }
47
48 public String getCanonicalName()
49 {
50 return "ISBLANK";
51 }
52
53 public TypeValuePair evaluate(final FormulaContext context,
54 final ParameterCallback parameters) throws EvaluationException
55 {
56 final int parameterCount = parameters.getParameterCount();
57 if (parameterCount < 1)
58 {
59 throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
60 }
61 final Object value = parameters.getValue(0);
62
63 final LValue raw = parameters.getRaw(0);
64 if (raw instanceof ContextLookup)
65 {
66 if (value == null)
67 {
68 return RETURN_TRUE;
69 }
70 }
71
72 return RETURN_FALSE;
73 }
74}