PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/libformula-1.1.3/source/org/pentaho/reporting/libraries/formula/lvalues/PostfixTerm.java

#
Java | 96 lines | 52 code | 12 blank | 32 comment | 4 complexity | 4ade2686855ab6690b0bc35566626351 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.lvalues;
  18. import org.pentaho.reporting.libraries.formula.EvaluationException;
  19. import org.pentaho.reporting.libraries.formula.operators.PostfixOperator;
  20. /**
  21. * Creation-Date: 02.11.2006, 10:20:27
  22. *
  23. * @author Thomas Morgner
  24. */
  25. public class PostfixTerm extends AbstractLValue
  26. {
  27. private PostfixOperator operator;
  28. private LValue value;
  29. private static final long serialVersionUID = -3652663226326546952L;
  30. public PostfixTerm(final LValue value, final PostfixOperator operator)
  31. {
  32. if (operator == null)
  33. {
  34. throw new NullPointerException();
  35. }
  36. if (value == null)
  37. {
  38. throw new NullPointerException();
  39. }
  40. this.operator = operator;
  41. this.value = value;
  42. }
  43. public PostfixOperator getOperator()
  44. {
  45. return operator;
  46. }
  47. public LValue getValue()
  48. {
  49. return value;
  50. }
  51. public TypeValuePair evaluate() throws EvaluationException
  52. {
  53. return operator.evaluate(getContext(), value.evaluate());
  54. }
  55. public String toString()
  56. {
  57. return "(" + value + operator + ')';
  58. }
  59. /**
  60. * Checks whether the LValue is constant. Constant lvalues always return the
  61. * same value.
  62. *
  63. * @return
  64. */
  65. public boolean isConstant()
  66. {
  67. return value.isConstant();
  68. }
  69. /**
  70. * Returns any dependent lvalues (parameters and operands, mostly).
  71. *
  72. * @return
  73. */
  74. public LValue[] getChildValues()
  75. {
  76. return new LValue[]{ value };
  77. }
  78. public Object clone() throws CloneNotSupportedException
  79. {
  80. final PostfixTerm o = (PostfixTerm) super.clone();
  81. o.value = (LValue) value.clone();
  82. return o;
  83. }
  84. }