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