1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.betwixt.expression;
17
18 /*** <p><code>ConstantExpression</code> represents a constant expression.</p>
19 *
20 * <p> In other words, {@link #evaluate} returns a value independent of the context. </p>
21 *
22 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
23 * @version $Revision: 155402 $
24 */
25 public class ConstantExpression implements Expression {
26
27 /*** The value of this expression */
28 private Object value;
29
30 /*** Base constructor
31 */
32 public ConstantExpression() {
33 }
34
35 /***
36 * Convenience constructor sets <code>value</code> property.
37 * @param value the Object which is the constant value for this expression
38 */
39 public ConstantExpression(Object value) {
40 this.value = value;
41 }
42
43 /***
44 * Evaluate expression against given context.
45 *
46 * @param context evaluate expression against this context
47 * @return current value of <code>value</code> property
48 */
49 public Object evaluate(Context context) {
50 return value;
51 }
52
53 /***
54 * Do nothing
55 * @see org.apache.commons.betwixt.expression.Expression
56 */
57 public void update(Context context, String newValue) {
58
59 }
60
61 /***
62 * Gets the constant value of this expression
63 * @return this expression's constant value
64 */
65 public Object getValue() {
66 return value;
67 }
68
69 /***
70 * Sets the constant value of this expression
71 * @param value the constant value for this expression
72 */
73 public void setValue(Object value) {
74 this.value = value;
75 }
76
77 /***
78 * Returns something useful for logging
79 * @return something useful for logging
80 */
81 public String toString() {
82 return "ConstantExpression [value=" + value + "]";
83 }
84 }