PageRenderTime 78ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/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. package org.pentaho.reporting.libraries.formula.function.information;
  18. import org.pentaho.reporting.libraries.formula.EvaluationException;
  19. import org.pentaho.reporting.libraries.formula.FormulaContext;
  20. import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue;
  21. import org.pentaho.reporting.libraries.formula.function.Function;
  22. import org.pentaho.reporting.libraries.formula.function.ParameterCallback;
  23. import org.pentaho.reporting.libraries.formula.lvalues.ContextLookup;
  24. import org.pentaho.reporting.libraries.formula.lvalues.LValue;
  25. import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair;
  26. import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType;
  27. /**
  28. * Document me!
  29. *
  30. * @author : Thomas Morgner
  31. */
  32. public class IsBlankFunction implements Function
  33. {
  34. private static final TypeValuePair RETURN_FALSE = new TypeValuePair(
  35. LogicalType.TYPE, Boolean.FALSE);
  36. private static final TypeValuePair RETURN_TRUE = new TypeValuePair(
  37. LogicalType.TYPE, Boolean.TRUE);
  38. private static final long serialVersionUID = 3352413434463488403L;
  39. public IsBlankFunction()
  40. {
  41. }
  42. public String getCanonicalName()
  43. {
  44. return "ISBLANK";
  45. }
  46. public TypeValuePair evaluate(final FormulaContext context,
  47. final ParameterCallback parameters) throws EvaluationException
  48. {
  49. final int parameterCount = parameters.getParameterCount();
  50. if (parameterCount < 1)
  51. {
  52. throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
  53. }
  54. final Object value = parameters.getValue(0);
  55. final LValue raw = parameters.getRaw(0);
  56. if (raw instanceof ContextLookup)
  57. {
  58. if (value == null)
  59. {
  60. return RETURN_TRUE;
  61. }
  62. }
  63. return RETURN_FALSE;
  64. }
  65. }